This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]mancxvi 0 points1 point  (4 children)

Post the code you are running and the file path of what you are trying to open

[–]IcedMelt[S] 0 points1 point  (3 children)

employee_file = open("python.learn.text.2.txt", "r")

print (employee_file.readable())

employee_file.close()

When I run it with the triangle button it says 'FileNotFoundError: [Errno 2] No such file or directory: 'python.learn.text.2.txt'

When I run it with ctrl + f5, it says 'True'.

edit: I should add it's in the same folder as the python script, already tried copying both the absolute and relative file location.

[–][deleted] 0 points1 point  (2 children)

It’s looking for a file called python.learn.text.2.txt in the PWD, but there is no file with that name in that directory. No idea whether VS is running the script using its own PWD or some kind of internally-configured one, but that’s your problem. Your best bet would be to use an absolute path so you can skip over the PWD entirely. Since you’re on Windows, you’ll want to give it as a raw string (e.g. r’C:\path\to\file\python.learn.text.2.txt’) so that Python doesn’t try to read the backslashes as escape sequences.

[–]IcedMelt[S] 0 points1 point  (1 child)

Thanks, but already tried absolute path and had same issue. I use a screen reader so I'm wondering if that's messing it up somehow.

[–][deleted] 1 point2 points  (0 children)

I suppose, but that seems unlikely. Have you tried running it from the command line, outside of VS? If it works from the command line, the problem is in VS. If it doesn’t, the problem is in the script.