Indeed i have a lot to learn about python but i have a question why replace function is not something what we could use?
i tried using this code
f=open("Te2.csv","w") s=open("Te.csv").read() s=s.replace('{','') s=s.replace('}','') s=s.replace('(','') s=s.replace(')','') s=s.replace("'","") s=s.replace(":",",") f.write(s) f.close() readFile = open("Te2.csv") lines = readFile.readlines() readFile.close() w = open("Te2.csv",'w') w.writelines([item for item in lines[:10]]) w.close()
and i came to se same result writen in the new file Te2
Acatari, Acatari, 0.0, Acatari, Acis, 183.1984286216621, Acatari, Adamclisi, 372.52641231771526, Acatari, Adjud, 200.36162156879055, Acatari, Afumati, 251.49065927408915, Acatari, Agas, 121.63622537704428, Acatari, Agigea, 409.27692015889204, Acatari, Aiud, 72.63968108608063, Acatari, Alba Iulia, 92.8322036095662, Acatari, Albac, 127.94211546456722,
First it's not the same output, there are unwanted white space and commas, but there is a deeper reason, we manipulate abstract data, we have a series of records, each record consisting of 2 names and a numerical value, and with this we can read and write csv files. This way of thinking gives better results than unstructured and unmaintanable string manipulations. Let's say there is a good way to do it and a bad way. Writing small helper functions is the good way IMHO.