Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Note on PEP 299

Reply
Thread Tools

Note on PEP 299

 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      07-20-2006
I don't like much the syntax of:
if __name__ == '__main__':

Some time ago I have read this PEP:
http://www.python.org/dev/peps/pep-0299/

And why it was refused:
http://mail.python.org/pipermail/pyt...ch/062955.html

I think the name of the standard main function may be just main(), so
there isn't the problem with the import (and *maybe* the problem with
multiple Python versions can be ignored with Python 3.0).

If a module contains the main(), the main() is executed when the module
is run alone. Otherwise you can import the module, with the main()
function managed as a normal function.

Bye,
bearophile

 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      07-21-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I don't like much the syntax of:
> if __name__ == '__main__':
>
> Some time ago I have read this PEP:
> http://www.python.org/dev/peps/pep-0299/
>
> And why it was refused:
> http://mail.python.org/pipermail/pyt...ch/062955.html
>
> I think the name of the standard main function may be just main(), so
> there isn't the problem with the import (and *maybe* the problem with
> multiple Python versions can be ignored with Python 3.0).


This idea, and a couple of variations, have come up in the Py3 discussions,
so something might be tried.

tjr



 
Reply With Quote
 
 
 
 
faulkner
Guest
Posts: n/a
 
      07-21-2006
http://home.comcast.net/~faulkner612...thon/mainer.py
turns
if __name__ == '__main__': sys.exit(main(sys.argv))
into
import mainer

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I don't like much the syntax of:
> if __name__ == '__main__':
>
> Some time ago I have read this PEP:
> http://www.python.org/dev/peps/pep-0299/
>
> And why it was refused:
> http://mail.python.org/pipermail/pyt...ch/062955.html
>
> I think the name of the standard main function may be just main(), so
> there isn't the problem with the import (and *maybe* the problem with
> multiple Python versions can be ignored with Python 3.0).
>
> If a module contains the main(), the main() is executed when the module
> is run alone. Otherwise you can import the module, with the main()
> function managed as a normal function.
>
> Bye,
> bearophile


 
Reply With Quote
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      07-21-2006
Faulkner:
> http://home.comcast.net/~faulkner612...thon/mainer.py


It's a bit of magic, I'll test it more, but it seems to work binding
the main() with Psyco too.
I have changed it a little (removed argv passed to the main and the
import of type, etc).
I don't know if/when I'll use it, but it seems nice enough.

Bye,
thank you,
bearophile

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
About Rational Number (PEP 239/PEP 240) Lie Python 25 12-18-2007 06:13 AM
PEP 299 and unit testing Ben Finney Python 5 10-29-2007 05:23 AM
PEP 3107 and stronger typing (note: probably a newbie question) Stephen R Laniel Python 160 07-22-2007 08:28 AM
RE: PEP 3107 and stronger typing (note: probably a newbie question) Hamilton, William Python 3 07-11-2007 10:57 PM
PEP for new modules (I read PEP 2) Christoph Becker-Freyseng Python 3 01-16-2004 04:26 PM



Advertisments