gpt4 book ai didi

python - 为什么我的硬编码数据没有写入文件?

转载 作者:行者123 更新时间:2023-12-01 06:53:52 26 4
gpt4 key购买 nike

def write_to_csv():
newRow = ['P12467','Cat','Ancora','Yes','Yes','D123456','Lost','14/09/2019','30/09/2019','return to owner',"290 Oak Avenue, BS79 8TR"]

//with open('DADSA 2019-20 CWK A DATA PETS.csv', 'wb') as csv_file:
with open("DADSA 2019-20 CWK A DATA PETS.csv", mode="a", newline='') as csv_file:
# reader = csv.reader(csv_file)
writer = csv.writer(csv_file)
for row in csv.reader(csv_file):
if row[0] == newRow[0]:
writer.writerow(newRow)

我收到此错误“对于 csv.reader(csv_file) 中的行:io.UnsupportedOperation:不可读”我不太明白它的意思。

最佳答案

您有一个拼写错误,您应该使用 newRow,而不是 csvFile,修复了以下代码:

def write_to_csv():
newRow = ['P12467','Cat','Ancora','Yes','Yes','D123456','Lost','14/09/2019','30/09/2019','return to owner',"290 Oak Avenue, BS79 8TR"]

#with open('DADSA 2019-20 CWK A DATA PETS.csv', 'wb') as csv_file:
with open("DADSA 2019-20 CWK A DATA PETS.csv", mode="a", newline='') as csv_file:
# reader = csv.reader(csv_file)
writer = csv.writer(csv_file)
for row in csv.reader(newRow):
if row[0] == newRow[0]:
writer.writerow(newRow)

关于python - 为什么我的硬编码数据没有写入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58885765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com