Discussion on some Code Issues

Roy Smith roy at panix.com
Sun Jul 8 14:17:41 EDT 2012


In article <mailman.1922.1341767824.4697.python-list at python.org>,
 Chris Angelico <rosuav at gmail.com> wrote:

> open("doc1.txt","r")
> 
> Python will look for a file called doc1.txt in the directory you run
> the script from (which is often going to be the same directory as your
> .py program).

Well, to pick a nit, the file will be looked for in the current working 
directory.  This may or may not be the directory you ran your script 
from.  Your script could have executed chdir() between the time you 
started it and you tried to open the file.

To pick another nit, it's misleading to say, "Python will look for...".  
This implies that Python somehow gets involved in pathname resolution, 
when it doesn't.  Python just passes paths to the operating system as 
opaque strings, and the OS does all the magic of figuring out what that 
string means.



More information about the Python-list mailing list