[英]How can I append a CSV file to an existing zip archive in Python?
[英]How can I replace a value in an existing excel csv file using a python program?
如何使用 python 程序更新现有.csv
文件中的值。 目前该文件已读入程序,但我需要能够使用我的程序更改此值,并且要对文件进行更改。 我怎样才能做到这一点? 这是我的程序:
import csv
file = open("productcodes.csv", "r")
for row in csv.reader(file):
print(row[1])
如何覆盖值row[1]
?
import csv
r = csv.reader(open('productcodes.csv'))
lines = [l for l in r]
for l in lines:
l[1] = "new value"
writer = csv.writer(open('productcodes.csv', 'w'))
writer.writerows(lines)
您无法真正替换现有文件中的值。 相反,您需要:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.