I am with a python script. I want to open a file to retrieve data inside. I add the right path to sys.path:
sys.path.append('F:\WORK\SIMILITUDE\ALGOCODE')
sys.path.append('F:\WORK\SIMILITUDE\ALGOCODE\DTW')
More precisely, the file file.txt I will open is in DTW folder, and I also add upper folder ALGOCODE. Then, I have command
inputASTM170512 = open("file.txt","r")
I have this present:
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
inputASTM170512 = open("ASTM-170512.txt","r")
IOError: [Errno 2] No such file or directory: 'ASTM-170512.txt'
Why? Do you have any idea?
open()checks only the current working directory and does not traverse your system path looking for the file. Onlyimportworks with that mechanism.You will either need to change your working directory before you open the file, with
os.chdir(PATH)or to include the entire path when trying to open it.