+ 1
No such file or directory
I've saved a file.txt that I want to open with python and script.py in the same folder but still when I run the program I get "no such file or directory". What can be the problem?
13 ответов
+ 2
Can you please share the code?
+ 4
//see this course too
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2446/?ref=app
+ 3
Did you see this tutorial
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2445/
?
+ 3
//and you didn't write file.read()
and make sure txt file is in same folder
file = open('mbox.txt','r')
lines = file.read()
print(lines)
+ 1
Yeah, sure just simple one, practicing the stuff with opening and reading files but got stuck at the very first step.
The code is:
file = open('mbox.txt','r')
print(file)
+ 1
Yeah, have seen, I have even added the hole path to the file as well but still the result is the same
+ 1
I think you should put the whole directory instead.
+ 1
Well I've just tried, failed(
+ 1
file = open('C:\\Users\\Matebook\\Desktop\\py4e\\ex_7\\mbox.txt','r')
print(file)
This doesn't work neither
+ 1
//Maybe you find some useful tips here
https://stackoverflow.com/questions/12201928/JUMP_LINK__&&__python__&&__JUMP_LINK-open-gives-ioerror-errno-2-no-such-file-or-directory
+ 1
Well, it's interesting: my first file I saved in .txt and it didn't work but then I decided to follow KnuckleBars advice and resaved the file by notepad for C++ and reran my program and it actually opened, my first txt file I created by using Windows text document tool
0
C++ file reading works way better than this.
0
Wow