OM Asphyxiate February 2016

Why is my result blank

I'm new to python, I'm using XLRD to read from an excel. I'm attempting to check the value of the first cell of each row against my variable mid using the following code

import xlrd

file_location="Z:/DASHBOARD/test.xls"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
mid=5348120284087186


for row_count in range(sheet.nrows):
    if (sheet.cell_value(row_count, 0)==mid):
        print sheet.row_values(row_count)

When I comment out the if statement it runs fine without checking, displaying the rows. With the if statement I get no results back. 5348120284087186 is the value in the first cell on multiple lines and the value of mid. Is there additional formatting I need to use with xlrd in order to find that value? I've attempted to not use the variable and just use 5348120284087186 as the comparison for the statement with the same results.

Answers


C S February 2016

You wrote: Attempted the fix with int() for row_count in range(sheet.nrows):

if (int(sheet.cell_value(row_count, 0))==mid): 
    print sheet.row_values(row_count) 

which resulted in error stating:

ValueError: invalid literal for int() with base 10: 'Run Date: ' 

That means the value in the cell isn't an integer like you thought, but 'Run Date: '.

Post Status

Asked in February 2016
Viewed 1,763 times
Voted 14
Answered 1 times

Search




Leave an answer