I was following a python tutorial about files and I couldn't open a text file while in the same directory as the python script. Any reason to this?
f = open("test.txt", "r") print(f.name) f.close() Error message:
Traceback (most recent call last): File "c:\Users\07gas\OneDrive\Documents\pyFileTest\ManipulatingFiles.py", line 1, in <module> f = open("test.txt", "r") FileNotFoundError: [Errno 2] No such file or directory: 'test.txt' Here's a screenshot of proof of it being in the same directory:
test.txtisn't in the current working directory. We don't know what that is. How are you running the code, and what are the environment options?File "c:\Users\07gas\OneDrive\Documents\pyFileTest\ManipulatingFiles.py", line 3, in <module> f = open(os.path.abspath("test.txt"), "r") FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\07gas\\test.txt'