(original) (raw)
On Mon, Jun 18, 2012 at 11:05 AM, Andrew McNabb <amcnabb@mcnabbs.org> wrote:
--- Bruce
I agree that having a boolean called "\_\_main\_\_" wouldn't add much value,
but I believe that recognizing a function called "\_\_main\_\_" could
potentially add a bit more value.
After executing the body of a script, the interpreter would
automatically call the "\_\_main\_\_" function if it exists, and exit with
its return value.
�
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.
This will increase the python learning curve, because people will need to learn both the old method and the new method, especially since code that is compatible with multiple python versions will need to continue to use the old method. It saves one or two lines:
� � if \_\_name\_\_ == '\_\_main\_\_':�main()
A \_\_main\_\_ boolean, that saves even less typing, and does not seem worth adding either.
-1 for both
�