onr
onr

Reputation: 296

Relative path of excel files, python

I am trying to access an Excel file in Python, but I'm getting the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'input/sales-feb-2014.xlsx'

Could you please help me defining the path of the file?

Python Code:

from xlrd import open_workbook    
sheet = open_workbook('input/sales-feb-2014.xlsx').sheet_by_index(0)    
print (sheet.cell_value(3,0))

The screenshoot shows the content of my directory:

Upvotes: 1

Views: 1132

Answers (1)

Jones1220
Jones1220

Reputation: 786

You either need to add the full path to open_workbook(your_full_path_comes_here) or change the directory you are working in before.

You can use the osmodule to before calling your variable.

import os

os.chdir(r'...your/path/input')

Upvotes: 2

Related Questions