Im use this path to go back 1 directory (back to directory 'dsa')
with open('../file.txt','r',encoding='utf-8') as f: print(f.read()) I get this error
Traceback (most recent call last): File "c:\Users\Secret\Desktop\Code\dsa\main.py", line 1, in <module> with open('../file.txt','r',encoding='utf-8') as f: FileNotFoundError: [Errno 2] No such file or directory: '../file.txt' my version of Python is 3.10.2
pathliboros.pathdsa? That being said, it's usually safer to build an absolute path instead of relying on relative paths. Depending on how you start your app, the CWD might not be what you hope/expect it to be.path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'file.txt').dsa, folderdsain folderCodeand folderCodein myDesktop. Filefile.txtis in folderCodeBut when I run code in folderCodeand filefile.txtin myDesktop. It's working