Function getting a reference to its own module

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Sep 17 07:29:51 CEST 2008


On Wed, 17 Sep 2008 13:52:13 +1200, greg wrote:

> Arnaud Delobelle wrote:
> 
>> Or:
>> 
>> import ModuleName as this_module
> 
> Or:
> 
> this_module = __import__(__name__)
> 
> then you don't have to change anything.


I like that solution! And it works regardless of whether the module 
holding it is imported, or is being executed from the commandline.

Thanks to everyone who made a suggestion.



-- 
Steven



More information about the Python-list mailing list