Returning the path of a file

Remco Gerlich scarblac at pino.selwerd.nl
Sat Jan 6 20:37:57 EST 2001


Daniel Klein <danielk at aracnet.com> wrote in comp.lang.python:
> I've search the Beazley book as well as the Python reference materials
> and can't find answers to these two basically simple questions:
> 
> 1) How to return the path of a file previously opened in read-only
> mode?
> 
> 	myfile = open("foo")

As others said, myfile.name is now "foo" and maybe you can reconstruct
something with that.

What I want to add - in general it's simply not possible to do better
than that. For instance, on Unix a file can have multiple filenames
because of linking. Or maybe someone is changing the directory structure
while you have the file open. Maybe the file is not actually a file on
the harddisk, but some device.

So maybe you should always open your files with the full path, if you
need this sort of thing often.

-- 
Remco Gerlich



More information about the Python-list mailing list