Search code examples
pythonxlrd

FileNotFoundError: [Errno 2] No such file or directory: error in xlrd


Language: Python-3.7.3, xlrd: 1.2.0

I am getting the below error while printing excel value as below.

Code:

import xlrd


class ExcelOperations():

    def open_excel(self, filepath):
        return xlrd.open_workbook(filepath)

    def get_column_values(self, filepath):
        return self.open_excel(filepath).sheet_by_index(0).cell_value(1, 0)


run = ExcelOperations()
print(run.get_column_values(run.get_column_values(localfilepath)))

Excel value

sheet1, A1(test),A2(test123)

Error:-

FileNotFoundError: [Errno 2] No such file or directory: 'test123'

Code looks to be correct and unsure why this error is coming out. Can someone assist me?


Solution

  • replace

    print(run.get_column_values(run.get_column_values(localfilepath)))
    

    with

    print(run.get_column_values(localfilepath))