1

I have simple code:

from xlrd import open_workbook

open_workbook('Book1.xls') 

No matter how I save the file (xls or xlsx) or how I change the path to the file (C:\Users\... or C:\Users...) I keep getting:

IOError: [Errno 2] No such file or directory: '(insert whatever is in place of Book1.xls)'

I don't know what I could be doing wrong. I'm not trying anything specific yet I just want it to not throw up an error.

2
  • is your script in the same directory as Book1.xls? Commented Nov 9, 2014 at 3:50
  • Actually this fixed it! thanks! does this always have to be the case even if you give it a full path to where it is? Commented Nov 10, 2014 at 5:36

2 Answers 2

3

You are not including whole path of the file. The path will be looks like:

file="C:\\USER\\TEST\\FILENAME"

or

file=r":\USER\TEST\FILENAME"

If you are using single slash then you need to use 'r' or else it will throw error.

Sign up to request clarification or add additional context in comments.

1 Comment

I was including the full path i just abbreviated for the question. but i did try the "r" thing and it still didnt work
1

you are not doing workbook("Book1.xls")

you are passing it a path (with directories) ... one of the folders in the path doesnt exist

this is probably because you do something like

directory="C:\Users\Blah\..."

when you need to do

directory = r"C:\Users\Blah\..."

other wise the backslashes serve to escape the next character

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.