Python xlrd返回一个无属性错误

我试图得到列表的列表与我的xlsx工作表中的某些单元格的值,但是当我运行它时,它说,没有称为值的属性。 当我运行没有“.value”方法的代码时,它将返回格式化我想要的列表的列表,但它们都具有值None。

import xlrd gmails = "/home/ro/Downloads/100 Gmail (1).xlsx" def open_worksheet(file_path): wb = xlrd.open_workbook(file_path) ws = wb.sheet_by_index(0) return ws def get_cell(worksheet, row, col): cell = worksheet.cell(row, col) def get_email_list(worksheet): email_list = [] first_gmail = [1, 3] first_password = [1, 3] first_recovery_gmail = [1, 5] for row in range(1, worksheet.nrows): gmail = get_cell(worksheet, first_gmail[0], first_gmail[1]) password = get_cell(worksheet, first_password[0], first_password[1]) recovery = get_cell(worksheet, first_recovery_gmail[0], first_recovery_gmail[1]) first_gmail[0] += 1 first_password[0] += 1 first_recovery_gmail[0] += 1 email_list.append([gmail.value, password.value, recovery.value]) return email_list print get_email_list(open_worksheet(gmails)) 

我的追踪

 Traceback (most recent call last): File "twitter.py", line 36, in <module> print get_email_list(open_worksheet(gmails)) File "twitter.py", line 33, in get_email_list email_list.append([gmail.value, password.value, recovery.value]) AttributeError: 'NoneType' object has no attribute 'value' 

 def get_cell(worksheet, row, col): cell = worksheet.cell(row, col) 

需要是:

 def get_cell(worksheet, row, col): return worksheet.cell(row, col)