I'm using with open('myFile', 'rb') as file: to read a file. When running the program with python myProgram.py everything works fine. But as soon I try to run it without cd-ing into the directory of myProgram.py and use an absolute path instead (like python /home/myName/myCode/myProgram.py I always get this error message: FileNotFoundError: [Errno 2] No such file or directory.
So why does open() behave differently depending on how the Python program is started? And is there a way to make things work even if starting with an absolute path?
I've already tried open('/home/myName/myCode/myfile', 'rb') but without success...
pwdin the directory where the program works it returns/home/myName/myCode. So that's exactly the directory where both my program and the file are.