How to obtain python file path

Gary Cramblitt garycramblitt_NOSPAM at comcast.net
Tue Apr 1 17:39:02 EST 2003


On Tue, 01 Apr 2003 21:58:12 +0000, 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
> 
> 
I might have seen something on the python cookbook website.  As I recall,
the basic technique is to force an exception, then use the info in the
exception object to get the path to the .py file causing the exception.




More information about the Python-list mailing list