Python xlrd returns 无属性错误

Python xlrd returns a no attribute error

我正在尝试获取包含我的 xlsx 工作表中某些单元格值的列表列表,但是当我 运行 它时,它说没有名为值的属性。当我 运行 没有“.value”方法的代码时,它将 return 一个按我想要的方式格式化的列表列表,但它们都具有值 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)