Python xlrd返回一个无属性错误

Python xlrd返回一个无属性错误,python,excel,xlrd,Python,Excel,Xlrd,我试图获取包含xlsx工作表中某些单元格值的列表,但当我运行它时,它显示没有名为value的属性。当我在没有“.value”方法的情况下运行代码时,它将返回一个列表,列表的格式是我想要的,但是它们都没有值 import xlrd gmails = "/home/ro/Downloads/100 Gmail (1).xlsx" def open_worksheet(file_path): wb = xlrd.open_workbook(file_path) ws = wb.sh

我试图获取包含xlsx工作表中某些单元格值的列表,但当我运行它时,它显示没有名为value的属性。当我在没有“.value”方法的情况下运行代码时,它将返回一个列表,列表的格式是我想要的,但是它们都没有值

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'
回溯(最近一次呼叫最后一次):
文件“twitter.py”,第36行,在
打印获取电子邮件列表(打开工作表(Gmail))
获取电子邮件列表中第33行的文件“twitter.py”
email_list.append([gmail.value,password.value,recovery.value])
AttributeError:“非类型”对象没有属性“值”
需要:

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

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

您的
get\u cell
函数中没有
return
语句,这意味着
gmail、password、recover
都被设置为
NoneType
(无返回函数将隐式返回
非类型
返回单元格
可能吗?@rnar啊,是的,谢谢。这是一个愚蠢的错误。在
获取单元格
函数中没有
返回
语句,这意味着
gmail、密码、恢复
都被设置为
非类型
(无返回函数将隐式返回
NoneType
返回单元格
可能吗?@rnar啊,是的,谢谢。这是一个愚蠢的错误。