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

Bruce Leban bruce at leapyear.org
Sat Nov 23 19:00:56 CET 2013


On Nov 22, 2013 8:06 PM, "Steven D'Aprano" <steve at pearwood.info> wrote:

> def __main__(argv):
>     ...
>
> is a cleaner (but less flexible) idiom that the current if __name__
> business, and simpler for people to learn.

If I had a time machine I would either do the __main__ function or
alternatively:

if __main__:
    ....

but alas I can't time travel and changing it will *not* be simpler to learn
because people will be seeing both the old idiom and the new idiom for a
long time. While it's interesting to discuss from the standpoint of what's
the best design, it's just not worth changing, IMHO.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131123/fee7bc28/attachment.html>


More information about the Python-ideas mailing list