- Joined
- Jan 18, 2012
- Messages
- 3
- Reaction score
- 0
Hi,
I am trying to replace spaces with underscores in a header record.
At this time I am only printing so I can see the results. When I get it to work I will write.
I am getting an attribute error on the line.replace.
Any ideas?
import csv
infile = open("fileexchange_response_12458229.csv", "r")
reader = csv.reader(infile)
record_cntr = 0
for line in reader:
if record_cntr == 0: #header line
print line # orig header line
line = line.replace(" ", "_") # replace spaces w/underscores
print line # header line fixed
record_cntr += 1
elif record_cntr <> 0 : #detail
print line
record_cntr += 1
I am trying to replace spaces with underscores in a header record.
At this time I am only printing so I can see the results. When I get it to work I will write.
I am getting an attribute error on the line.replace.
Any ideas?
import csv
infile = open("fileexchange_response_12458229.csv", "r")
reader = csv.reader(infile)
record_cntr = 0
for line in reader:
if record_cntr == 0: #header line
print line # orig header line
line = line.replace(" ", "_") # replace spaces w/underscores
print line # header line fixed
record_cntr += 1
elif record_cntr <> 0 : #detail
print line
record_cntr += 1