#πŸ”’ FileNorFoundError even though the file exists

15 messages Β· Page 1 of 1 (latest)

prime sorrel
#

Im trying to work with a text file named "learning_python.txt". It's located in the same directory as my python file "working_with_file.py". When I run the code it says "FileNotFoundError: [Errno 2] No such file or directory:" I tried using both absolute path and just a regular path.

slate caveBOT
#

@prime sorrel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

pine aurora
#

But I haven't used a Mac in like 15 years, so idk for sure.

prime sorrel
#

i tried checking the current directory, and weirdly its not the directory where the file was saved. And then i tried to check whether the file exists both with absolute path and just the path. And it doesnt exist

prime sorrel
pine aurora
#

Did you try just removing the Macintosh HD/ from the path?

prime sorrel
#

omg it works, thank you!

pine aurora
#

Figured it would. The Macintosh HD/ drive must not be a part of the path like it is in Windows for some reason.

prime sorrel
#

still kinda weird that current path is not the path that i saved both files in, but oh well :B

#

!closed

slate caveBOT
#
Did you mean:

!close

prime sorrel
#

!close

slate caveBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.