[Python-ideas] Replacing the if __name__ == "__main__" idiom (was Re: making a module callable)

Haoyi Li haoyi.sg at gmail.com
Sun Nov 24 04:44:41 CET 2013


> It's hard to see how they could. How would you *install* an import hook
before __main__ got imported?

By doing crazy things like trying to reload __main__, or by deleting
__main__ from the system modules and trying to re-import it, or by using
introspection to load the file containing __main__ and stuffing it into
sys.modules, or doing other nasty things.

It's hard to see how any of these would work. I just wanted to confirm
"they don't".


On Sat, Nov 23, 2013 at 7:35 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:

> Haoyi Li wrote:
>
>> Import hooks don't work with __main__ =( I spent a while trying to get it
>> to work when working on MacroPy, to no avail.
>>
>
> It's hard to see how they could. How would you *install*
> an import hook before __main__ got imported?
>
> --
> Greg
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131123/ff4ce8a6/attachment-0001.html>


More information about the Python-ideas mailing list