[Python-ideas] Just main (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Mon Jun 18 22:13:50 CEST 2012


On Mon, 18 Jun 2012 14:09:33 -0600 Andrew McNabb <amcnabb at mcnabbs.org> wrote:

On Mon, Jun 18, 2012 at 12:39:05PM -0700, Bruce Leban wrote: > > The special value of name and the proposed main() function are both > a bit magic. However, when I write if name == 'main' it's at least > clear that that if statement will be executed. It's just a question of > when the condition is true and if I don't know I can find out fairly > easily. (As I did the first time I saw it and probably other people on this > list did too.) On the other hand, it's not at all obvious that a function > named main will be executed automagically.

Given that C, Java, and numerous other languages automagically execute a function called "main", I would argue that a "main" function would actually be less surprising than "if name == 'main'" for most new Python users.

Yes, a main function would be reasonable, especially now that we have main.py files in packages.

Massimo's suggestion of a decorator, OTOH, sounds useless: how would it help in any way?

Regards

Antoine.



More information about the Python-ideas mailing list