我无法通过g-spread列出所有工作表

时间:2019-09-26 16:31:01

标签: python gspread

第98行的功能“ navigate_sheet”上 第99行不显示工作表列表

我不太确定要尝试什么

https://pastebin.com/Mzy3R5cn

class InputData:
    def __init__(self):
        # use creds to create a client to interact with the Google Drive API
        self.scope = ['https://spreadsheets.google.com/feeds',
                 'https://www.googleapis.com/auth/drive']
        self.creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', self.scope)
        self.client = gspread.authorize(self.creds)
        self.sheet = ""
        self.error = "[!] There was a critical error that broke the program!"
    def navigate_sheet(self):
        worksheet_list = self.sheet.worksheets()
        print(worksheet_list)

预期结果:

  

显示工作表列表实际结果:“ AttributeError:   “工作表”对象没有属性“工作表””

1 个答案:

答案 0 :(得分:0)

我认为您忘记了初始化sheet数据成员。

https://gspread.readthedocs.io/en/latest/user-guide.html#opening-a-spreadsheet

此链接可以帮助您初始化工作表成员