A
Angelo Secchi
Hallo,
I have the following problem. I'm trying to clean a database whose lines
look like:
"2/G DM" "HOE" 0 "R5D2" 1 0 0 0
in particular I need to remove the ".
Here my code
def wash(a) :
a=string.replace(a,'"','')
return a
data=file("prova.txt",'r')
data_clean=file("prova_clean.txt",'w')
temp_string = data.readline()
while len(temp_string) != 0:
temp_field=string.split(temp_string,'\t')
print temp_field
temp_field=map(wash,temp_field)
print temp_field
data_clean.write(temp_field)
temp_string = data.readline()
data.close()
data_clean.close()
Of course I receive an error in line "data_clean.write(temp_field)"
saying "TypeError: argument 1 must be string or read-only character
buffer, not list". I'm a newbie and reading tutorials around I was not
able to find the best solution to my problem. Could anybody help me?
I also read in this mailing list that there exists a specific list for
newbie (called python tutor mailing list) but I was not able to find it.
Any suggestions?
Thanks
Angelo
I have the following problem. I'm trying to clean a database whose lines
look like:
"2/G DM" "HOE" 0 "R5D2" 1 0 0 0
in particular I need to remove the ".
Here my code
def wash(a) :
a=string.replace(a,'"','')
return a
data=file("prova.txt",'r')
data_clean=file("prova_clean.txt",'w')
temp_string = data.readline()
while len(temp_string) != 0:
temp_field=string.split(temp_string,'\t')
print temp_field
temp_field=map(wash,temp_field)
print temp_field
data_clean.write(temp_field)
temp_string = data.readline()
data.close()
data_clean.close()
Of course I receive an error in line "data_clean.write(temp_field)"
saying "TypeError: argument 1 must be string or read-only character
buffer, not list". I'm a newbie and reading tutorials around I was not
able to find the best solution to my problem. Could anybody help me?
I also read in this mailing list that there exists a specific list for
newbie (called python tutor mailing list) but I was not able to find it.
Any suggestions?
Thanks
Angelo