我想创建一个python脚本,将围绕一个字符串的一部分报价封装字符串的一部分,经过3逗号使用python后3个逗号
因此,如果输入的数据是这样的:
1234,1,1/1/2010,This is a test. One, two, three.
我想蟒蛇字符串转换:
1234,1,1/1/2010,"This is a test. One, two, three."
的报价总是需要经过3个逗号添加
我使用Python 3.1.2,并迄今以下:当我尝试运行它,并不会产生输出
你可以看到什么是错的
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()
脚本立即关闭?
感谢
'if count =“3”:'的语法错误。为什么'3'在引号中? – bernie 2010-10-21 04:22:19