【发布时间】:2014-04-13 11:15:01
【问题描述】:
我正在尝试将私人 google 电子表格保存到 csv 中。我找到了另一个解决了这个问题的线程(Download a spreadsheet from Google Docs using Python),但是答案可以追溯到 2012 年。我尝试使用一个解决方案,但我遇到了错误。这是我目前使用的代码
import csv
import gspread
// used the actual username, password and doc-id in the python script
username = "username"
password = "password"
docid = "doc-id"
client = gspread.login(username, password)
spreadsheet = client.open_by_key(docid)
for i, worksheet in enumerate(spreadsheet.worksheets()):
filename = docid + '-worksheet' + str(i) + '.csv'
with open(filename, 'wb') as f:
writer = csv.writer(f)
writer.writerows(worksheet.get_all_values())
这是 IDLE 抛出的错误
writer.writerows(worksheet.get_all_values())
TypeError: 'str' does not support the buffer interface
您一定已经意识到,我对 python 非常陌生,我正在努力解决这个问题。谁能指出我使用的代码有什么问题?
【问题讨论】:
标签: python csv python-3.x google-docs