How can a function know what module it's in?

Steve Holden steve at holdenweb.com
Wed Nov 12 08:07:42 EST 2008


Joe Strout wrote:
> Some corrections, to highlight the depth of my confusion...
> 
> On Nov 11, 2008, at 9:10 PM, Joe Strout wrote:
> 
>>     doctest.testmod(mymodule)
>>
>> This actually works fine if I'm importing the module (with the
>> standard name) somewhere else
> 
> Actually, it does not.
> 
>> I noticed that a function object has a __module__ attribute, that is a
>> reference to the module the function is in.
> 
> And no, it isn't; it's the NAME of the module the function is in.

Are you sure it's not a reference to the name? ;-)

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list