[Python-ideas] 'from os.path import FILE, DIR' or internal structure of filenames

Terry Reedy tjreedy at udel.edu
Sun Sep 29 21:19:38 CEST 2013

On 9/28/2013 11:28 PM, INADA Naoki wrote:
> os.path.abspath(__file__) returns wrong path after chdir.

So grab the path before chdir (which most programs do not do).

> So I don't think abspath of module can be trivially and reliably derived
> from existing values.

It apparently can if you do so in a timely fashion.
Grabbing it as soon as possible is the obvious time to do it.

> $ cat foo.py
> import os

foopath = os.path.abspath(__file__)
Now print it or do whatever you want with it.

Terry Jan Reedy

More information about the Python-ideas mailing list