我试图在我的xlsx工作表中找到包含某些单元格值的列表,但是当我运行它时,它表示没有名为value的属性。当我运行没有" .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'
答案 0 :(得分:0)
def get_cell(worksheet, row, col):
cell = worksheet.cell(row, col)
需要:
def get_cell(worksheet, row, col):
return worksheet.cell(row, col)