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

Guido van Rossum guido at python.org
Mon Nov 25 04:16:32 CET 2013


On Sun, Nov 24, 2013 at 7:08 PM, INADA Naoki <songofacandy at gmail.com> wrote:

> I want to have callable main function to allow script can be executed
> directly or from other function.
>
> def main():
>     <blah>
>
> if is_main():
>     main()
>
> is not shorter than
>
> @mainfunction
> def main():
>     <blah>
>
> But I like:
>
> def __main__():
>     <blah>
>

I had a few other arguments also against the decorator. (Like less magic.
:-)

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131124/f07967ed/attachment.html>


More information about the Python-ideas mailing list