+ 1

python func open() doesn't see the file in directory

py 3 guys,the file really in same directory where .py located is please,don't blame me if the code contains rly stupid mistakes THANK YOU GOD BLESS YOU CODE: filename = open('input1.txt') filename.replace(" ","\n") file = filename.read() filename.close() l=len(file) a=file.readline() a.replace("\n","") X=int(a[0]) N=int(a[1]) T=int(a[2]) t=240 u=N-X z=u*T g=t/z print(str(int(g)))

3rd Oct 2017, 7:23 PM
inva510n
inva510n - avatar
5 Answers
+ 8
What I mean is that the variable filename is the file handler. It does not have a .replace() method. If you get the "file not found" error, I can think of three things: - either the file is indeed not there - it is there, but has a 'hidden' attribute - you run the python script command from a different path and it can't find the file Try adding (at the very beginning, before the code you wrote): import os print(os.listdir()) That should list you the files it sees in the current directory. If you can't see the 'input1.txt' file there, nor can your script.
3rd Oct 2017, 8:39 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 7
What kind of error you get?
3rd Oct 2017, 7:58 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 7
Hmmm... I would assume that filename.replace won't work, as it's a string method not file object method. Doesn't the parser let you know which line the error is located in?
3rd Oct 2017, 8:03 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
0
i got FileNotFoundError
3rd Oct 2017, 7:59 PM
inva510n
inva510n - avatar
0
i don't know how to use parser for py yet can you please tell me more about "filename.replace won't work"??
3rd Oct 2017, 8:21 PM
inva510n
inva510n - avatar