[Tutor] Open file error
Alan Gauld
alan.gauld at freenet.co.uk
Tue Jan 17 19:06:33 CET 2006
> I am trying to run (on an XP box) a simple open file using this:
> f = open(r'C:\Test.txt', 'r')
> IOError: [Errno 2] No such file or directory: 'C:\Test.txt'
> I know for sure that the file is there
> Furthermore, how does Python assumes the search path?
There is no search, you have specified exactly where to look so
Python will look there and nowhere else. But it may not be able
to open the file if it belongs to someone else who has denied access.
Have you checked the security settings on C:\Test.txt? Thats the
only other thing that I can think of if you are sure that a file called
Test.txt exists in the root directory of the C drive.
> How does it knows drive lettering, network mapping etc?
Because you explicitly tell it.
If you don;t specify the full path it will look in the current directory.
You can find that with the os.getcwd() function. See my OS topic
for more on how to test file status...
http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm
HTH,
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list