[Python-ideas] making a module callable

Eric Snow ericsnowcurrently at gmail.com
Fri Nov 22 19:20:43 CET 2013


On Fri, Nov 22, 2013 at 10:01 AM, Michael Foord <fuzzyman at gmail.com> wrote:
> On 22 November 2013 16:45, Gregory P. Smith <greg at krypto.org> wrote:
>> Agreed, formalizing how to do the replacement trick sounds good. It'd be
>> ideal for a module to not need to know its own name within the code doing
>> the replacement and for it to not need to reimplement common interface bits
>> in a replacement class so that it quacks like a module.
>>
> Well, it just has to use __name__. Any formalisation that doesn't get passed
> the name is going to have to use frame trickery to get the name which is
> just smelly.

With a special-case for __name__ == "__main__" of course. :)

-eric


More information about the Python-ideas mailing list