我有这个问题。我让这个功能在csv文件上做了一些修复。它只在我第一次打电话时有效,但不是第二次。 感谢您的帮助!我正在调用一个函数两次,但它只在第一次运行
import csv
file = open('original.csv', 'r')
fileOut = open('fixed.csv', 'wb')
# Make a list out of the csv content
read = [x for x in csv.reader(file)]
writer = csv.writer(fileOut, delimiter=',', quoting=csv.QUOTE_NONE)
# Function to make changes to the csv
def rep(field, uno, dos):
for x in read:
x[field] = x[field].replace(uno, dos)
writer.writerow(x)
# First call
rep(0, 'COMISARIA ', '')
# Second call
rep(4, 'AVDA', '')
fileOut.close()
多少行没有原始CSV有,又有多少行贵固定CSV有哪些? – Kevin
你看到的问题到底是什么?什么是投入,实际产出和预期产出? – interjay
您是否记得.close()您的输入文件? – Symmitchry