Getting the name of the file that imported current module

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Jul 5 00:42:35 EDT 2010


On 05/07/2010 00:25, Michael Torrie wrote:
> 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.

You're absolutely correct, thou shalt not post late at night when very 
tired. :)

Cheers.

Mark Lawrence




More information about the Python-list mailing list