How to obtain python file path

Dan Grassi dan at grassi.org
Tue Apr 1 17:18:57 EST 2003


Not Quite,

I need b to know it's path, not the script that imports b.

Dan

In <b6d260$lg$1 at news.eusc.inter.net> Daniel Dittmar  wrote:
> 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