Getting the name of the file that imported current module

Michael Torrie torriem at gmail.com
Sun Jul 4 19:25:58 EDT 2010


On 07/04/2010 03:17 PM, Mark Lawrence wrote:
> 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'

I think this is exactly opposite of what he was asking for.

Given than any number of modules can import other modules but each
module really only exists once in the Python object space (normally)
would mean that what the OP is asking for isn't possible.



More information about the Python-list mailing list