Getting the name of the file that imported current module

Mark Lawrence breamoreboy at yahoo.co.uk
Sun Jul 4 17:17:52 EDT 2010


On 04/07/2010 22:05, Tobiah wrote:
> foo.py:
>
> import bar
> bar.show_importer()
>
> output:
>
> 'foo' or 'foo.py' or 'path/to/foo' etc.
>
> Possible?
>
> Thanks,
>
> Tobiah

 >>> import re
 >>> re.__file__
'C:\\Python26\\lib\\re.pyc'

HTH.

Mark Lawrence.




More information about the Python-list mailing list