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

Paul Moore p.f.moore at gmail.com
Mon Nov 25 23:28:32 CET 2013


On 25 November 2013 21:44, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Mon, 25 Nov 2013 13:22:53 -0800
> Guido van Rossum <guido at python.org> wrote:
>>
>> (I don't get the point against my is_main() proposal that it also uses
>> magic. It's a builtin. *Of course* it is allowed to use magic.)
>
> Just because it is allowed to use magic doesn't mean it's a good idea,
> though. I can imagine people struggling to understand how it works
> (and how they can replicate it), while the current idiom is very easy to
> understand.
>
> I still don't think the current idiom is problematic, so I'm -0.8 on
> the whole thing :-)

Also, the current idiom is in use in an immense amount of
documentation and existing code. That's not going away, so people now
have *two* ways of saying the same thing. And to be honest, I suspect
many of the "old hands" will simply ignore the new idiom and continue
using (and teaching others, by example if nothing else) the old one -
so it's not even as if the old idiom is going to disappear.

If we were starting from scratch, is_main() might be a reasonable
proposal, but I don't see the value given that we're not. I'm
definitely at least -0.5. And I can't see myself ever using the new
style even if it's implemented.

Paul.

PS This is assuming that nobody is suggesting breaking "if __name__ ==
'__main__'". If they are, then that's a whole different debate.


More information about the Python-ideas mailing list