我正在编写一个 python(ver 3) 脚本来使用 gspread 访问谷歌文档。
1) import gspread
2) from oauth2client.service_account import ServiceAccountCredentials
3) scope = ['https://spreadsheets.google.com/feeds']
4) credentials = ServiceAccountCredentials.from_json_keyfile_name(r'/path/to/jason/file/xxxxxx.json',scope)
5) gc = gspread.authorize(credentials)
6) wks = gc.open("test").sheet1
Run Code Online (Sandbox Code Playgroud)
测试是一个谷歌表,它似乎被打开并且阅读正常,但是如果我尝试从 Office excel 文件中读取它会给我错误。这是它们的外观:
test 和 mtg 所在的文件夹与我在 json 文件中收到的电子邮件共享。这两个文件也与该电子邮件共享。
尝试:
wks = gc.open("mtg.xls").sheet1
Run Code Online (Sandbox Code Playgroud)
和
wks = gc.open("mtg.xls").<NameOfFirstSheet>
Run Code Online (Sandbox Code Playgroud)
和
wks = gc.open("mtg").<NameOfFirstSheet>
Run Code Online (Sandbox Code Playgroud)
错误:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/gspread/client.py”,第 152 行,在 open raise SpreadsheetNotFound gspread.exceptions.SpreadsheetNotFound
在Mac OS上使用Python 3.4,mysql。已经安装了mysql,pymysql,mysqlclient-python
import pymysql
import pymysql.cursors
import _mysql
connection = pymysql.connect(host='localhost',user='sth',password ='', db = 'mydb')
query = "INSERT INTO mydb (card, price,color,index1) VALUES ('cardeeef','3.24','B','frsss')"
cur = connection.cursor
cur.execute(query)
results =cur.fetchall()
Run Code Online (Sandbox Code Playgroud)
不知道还需要什么,所以它知道“ .execute”