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

Andrew Barnert abarnert at yahoo.com
Tue Nov 26 18:37:28 CET 2013


On Nov 26, 2013, at 8:34, Alan Cristhian Ruiz <alan.cristh at gmail.com> wrote:

> I think the need to change * if __ name__ == "__main__": * is capricious and obsessive. The current rule is better than anything that has been suggested so far. I never had any problems with the * if __ name__ == "__main__": *. Also in python there are other things much more difficult to learn and use, such as metaclasses.

Although I agree with your main point, I don't think that's a very good argument. 

__main__ is something novices have to learn early and use in code regularly; metaclasses are something only experienced developers use, and not that often (and that's even if you count using stdlib metaclasses to, e.g., create ABCs, which doesn't really require you to understand how they work). It's perfectly reasonable for an "expert" feature to be more difficult to learn than a novice feature.

Also, Python doesn't have a queue of improvements to be scheduled to a team of developers. Things get improved if someone is motivated enough to write the code and drive the idea to consensus and/or BDFL approval. So, improving this would have very little bearing on improving things you care about more.


More information about the Python-ideas mailing list