How to obtain python file path

Dan Grassi dan at grassi.org
Tue Apr 1 16:58:12 EST 2003


Not quite, that only provides the path to the initial .py file.

With a directory structure:
fa
    a.py
    fb
        b.py

cd .../fa
execute a.py
where a adds fb to sys.path
a imports b.py

I need b.py to report it's path which would be .../fa/fb

Dan


In <slrnb8jusc.5u1.ramen at lackingtalent.com> Dave Benjamin  wrote:
> import os, sys
> print os.path.abspath(sys.argv[0])
> 




More information about the Python-list mailing list