I am trying to create a python script that adds quotations around part of a string, after 3 commas
So if the input data looks like this:
1234,1,1/1/2010,This is a test. One, two, three.
I want python to convert the string to:
1234,1,1/1/2010,"This is a test. One, two, three."
The quotes will always need to be added after 3 commas
I am using Python 3.1.2 and have the following so far:
i_file=open("input.csv","r")
o_file=open("output.csv","w")
for line in i_file:
tokens=line.split(",")
count=0
new_line=""
for element in tokens:
if count = "3":
new_line = new_line + '"' + element + '"'
break
else:
new_line = new_line + element + ","
count=count+1
o_file.write(new_line + "\n")
print(line, " -> ", new_line)
i_file.close()
o_file.close()
The script closes immediately when I try to run it and produces no output
Can you see what's wrong?
Thanks