How to obtain python file path

Daniel Dittmar daniel at dittmar.net
Tue Apr 1 17:00:07 EST 2003


Dan Grassi wrote:
> 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

 >>> import string
 >>> string.__file__
'D:\\Python22\\lib\\string.py'

Daniel





More information about the Python-list mailing list