I'm trying to get a list of list with the values of certain cells within my xlsx worksheet but when I run it, it says there is no attribute called value. when I run the code without the ".value" method it will return a list of lists formatted the way I want but they all have the 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))
My Traceback
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)
needs to be:
def get_cell(worksheet, row, col):
return worksheet.cell(row, col)