我想做什么:
从互联网下载XLS文件(在我的代码示例中,我从Google表格中提取,但将来我将直接通过网址下载)
保存该文件的新副本,并将日期时间添加到文件名中。 (所以我有一个文件夹,包含testexcel_05_24_2016.xlsx,testexcelt_05_25_2016.xlsx等)
过度写一个现有的"主人"文件。即将testexcel保存为masterexcel.xls
这是我的代码:
import gspread
#export GOOGLE_APPLICATION_CREDENTIALS="XXXXX"
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('XXXX', scope)
gc = gspread.authorize(credentials)
wks = gc.open("TestSheet").sheet1 #this is the sheet I'm opening
nst = open('NSTtest.xlsx', 'w') #trying to open 'master file'
nst.write(wks) #trying to overwrite master file with new file
nst.close()
os.rename(wks, "wks.xlsx") #trying to save new file. This is where I would add the date time
我运行时遇到的错误是:
Traceback (most recent call last):
File "gspreadtest.py", line 14, in <module>
nst.write(wks)
TypeError: expected a character buffer object
Aschs-MacBook-Air:learnpython aschharwood $
非常感谢您的帮助!