[Tutor] problem in opening files
Alan Gauld
alan.gauld at btinternet.com
Sun Jun 24 21:39:16 CEST 2012
On 24/06/12 19:17, promis at yorku.ca wrote:
> >>> fo = open('mort.txt') THIS IS WHAT I TYPED AND THE MESSAGE
> FOLLOWS
>
> Traceback (most recent call last):
> File "<pyshell#1>", line 1, in <module>
> fo = open('mort.txt')
> IOError: [Errno 2] No such file or directory: 'mort.txt'
>>>>
>
> The file mort.txt certainly seems to me to exist. I can see it on my
> desktop. It was a small sample file that I just created to test this
Python is not psychic. It cannot guess where your file lives so it just
looks in the current directory - the one from which you ran Python.
If that's not where the file exists then you get an error.,
You need to provide the full path to the file or run the program from
the same folder where the file lives.
You can get similar problems if you don't have the right access
permissions but since you created this file that's not going to
be the problem here.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list