类实例作为全局变量

时间:2018-12-11 21:12:43

标签: python-3.x oauth2client pygsheets

我正在尝试做这样的事情:

import pygsheets
from oauth2client.service_account import ServiceAccountCredentials
scope = [
    'https://spreadsheets.google.com/feeds',
    'https://www.googleapis.com/auth/drive'
     ]
credentials01 = ServiceAccountCredentials.from_json_keyfile_name('creds01.json', scope)
def make_connection():
    global file01
    file01 = pygsheets.client.Client(credentials01)
def fetch_data():
    wb01 = file01.open('Database System 2')
make_connection()
fetch_data()

但是,它引发了一个名称错误,即“未定义file01”。有什么办法可以解决吗?

0 个答案:

没有答案