For more clarifying information, I am using a Ubuntu 20.04. I am receiving the following error when trying to read a text file from a different directory: FileNotFoundError: [Errno 2] No such file or directory
Say that the python code "code.py" that I am trying to run resides in Folder1. The text file "test.txt" that I am trying to read off of is in Folder2, where the relative pathing from "code.py" is "../Folder2/test.txt". However, when I am using: from pathlib import Path and
PATH = Path("..\Folder2\test.txt"), I receive the error. Is there a better way to go about this? Thank you in advance.
You should use os.path.join(), as it was built to work cross-platform(Linux/Mac/Windows).
Receiving FileNotFoundError: [Errno 2] No such file or directory