在 python 中使用局部变量将 CSV 导入 Google 工作表?
Import CSV into Google Sheets with local variable in python?
我的程序从 ftp 服务器下载 csv,对格式进行修改,然后我目前无法将其上传到 google 工作表。当我 select 一个本地文件时,它可以工作....
目前,当我使用 writer 变量时,它显示 TypeError: '_csv.writer' object is not iterable
with open('test5.csv', 'w') as f:
# Overwrite the old file with the modified rows
writer = csv.writer(f)
writer.writerows(new_rows)**
print("done!")
print(str(writer))
gc = gspread.service_account(
filename='xxx.json')
print("Connected TO GOOGLE")
**gc.import_csv("my-sheet-id", writer)**
print("UPLOADED")
我认为 gspread 正在寻找 csv 文件并且不接受变量?我可以使用 writer 将 csv 文件写入局部变量而不是我的 p 吗?我问这个是因为我想让这个服务器支持。
您在此处传递 writer
:
gc.import_csv("my-sheet-id", writer)
你不是要传入'test5.csv'吗?
附带说明一下,当您的代码中有随机星星时,它会非常混乱。你应该在发布到 SO 之前删除那些。
我的程序从 ftp 服务器下载 csv,对格式进行修改,然后我目前无法将其上传到 google 工作表。当我 select 一个本地文件时,它可以工作....
目前,当我使用 writer 变量时,它显示 TypeError: '_csv.writer' object is not iterable
with open('test5.csv', 'w') as f:
# Overwrite the old file with the modified rows
writer = csv.writer(f)
writer.writerows(new_rows)**
print("done!")
print(str(writer))
gc = gspread.service_account(
filename='xxx.json')
print("Connected TO GOOGLE")
**gc.import_csv("my-sheet-id", writer)**
print("UPLOADED")
我认为 gspread 正在寻找 csv 文件并且不接受变量?我可以使用 writer 将 csv 文件写入局部变量而不是我的 p 吗?我问这个是因为我想让这个服务器支持。
您在此处传递 writer
:
gc.import_csv("my-sheet-id", writer)
你不是要传入'test5.csv'吗?
附带说明一下,当您的代码中有随机星星时,它会非常混乱。你应该在发布到 SO 之前删除那些。