Python Forum

Full Version: Opening files in same directory as script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The textbook I am using didn't specify this problem so I want someone to help me.
I have a text file that is in the same directory as the script file. When I call file open, it tells me it cannot see it.
filehandle = open('box.txt')
The code returns an error that the file or directory doesn't exist.
What should I do to open it.
Your code appears to be correct. Can you post the full traceback error message?
Also, in which directory are you running the script from?
(May-28-2020, 05:22 PM)GOTO10 Wrote: [ -> ]Your code appears to be correct. Can you post the full traceback error message?
The error message is:
FileNotFoundError: [Errno 2] No such file or directory: 'box.txt'

I have seen what the problem was just from a question a user asked.
I did not open the folder in vs code and the editor was reading from another folder. So, because someone asked about the folder, I decided to open the folder directly in vs code and it saw the file.
Thanks