Ad

Have An Error FileNotFoundError: [Errno 2] No Such File Or Directory: 'test.txt'

- 1 answer

f = open("test.txt")
        ^

FileNotFoundError: [Errno 2] No such file or directory: 'test.txt' I have that text document but it still happens to be an error. It is no duplicate.

Ad

Answer

I bet you do not have this file. At least not in the same directory from where you run your python script. If you put test.txt into /tmp/ and you execute python from /home/user/, you will get this exception even when your script is in /tmp/ as well.

So in this case, cd to /tmp/ and run your program from there.

Ad
source: stackoverflow.com
Ad