I am trying to put dynamic values as an arguments in open_workbook() function of xlrd but it is giving error.
My sample code is:
*******************************************
import xlrd,os
filepath=r’C:\Users\JJ\Desktop\JustForTest\2012_09_10′
for root,dirs,files in os.walk(filepath):
abc=files[0] # To convert List to string, files will be like ['Samplexyx.xls']
wb=xlrd.open_workbook(abc)
sh=wb.sheet_by_index(0)
for rownum in range(sh.nrows):
print(sh.row_values(rownum))
*******************************************
In the above code, the value of abc dynamically changes.
When I run above code, it is giving error as: IOError: [Errno 2] No such file or directory: ‘Samplexyx.xls’
I am new to using xlrd and Python. What should I do to dynamically open xls files using xlrd and python?
its not looking in the right directory for the file