[Python-ideas] Just main (original) (raw)
Bruce Leban bruce at leapyear.org
Mon Jun 18 21:39:05 CEST 2012
- Previous message: [Python-ideas] Just __main__
- Next message: [Python-ideas] Just __main__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Jun 18, 2012 at 11:05 AM, Andrew McNabb <amcnabb at mcnabbs.org> wrote:
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
--- Bruce Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120618/2a2c8f7a/attachment.html>
- Previous message: [Python-ideas] Just __main__
- Next message: [Python-ideas] Just __main__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]