我在 csv 文件中有一系列文本:
7858.35924983374[%2C]1703.69341358077[%2C]-3.075},7822.85045874375[%2C]1730.80294308742[%2C]-3.53962362760298}
有没有技巧来替换 [%2C] ?
with open('C:\IM\C3D\CommonLibraries\unewuoxhwt5k.wi2.conduit', "rb") as fin, open('C:\IM\C3D\CommonLibraries\unewuoxhwt5k.wi2.conduit', "wb") as fout:
reader = csv.reader(fin)
writer = csv.writer(fout)
for row in reader:
new_row = []
for item in row:
new_row.append(item.replace('[%2C]', ','))
print row, "->", new_row
writer.writerow(new_row)
现在我得到一个文件,但它是空的,我得到这个错误消息:
Traceback (most recent call last):
File "<pyshell#6>", line 6, in <module>
for item in row:
NameError: name 'row' is not defined