By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

Note on PEP 299

P: n/a
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

Jul 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

<be************@lycos.comwrote in message
news:11**********************@m79g2000cwm.googlegr 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

Jul 21 '06 #2

P: n/a
http://home.comcast.net/~faulkner612...thon/mainer.py
turns
if __name__ == '__main__': sys.exit(main(sys.argv))
into
import mainer

be************@lycos.com 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
Jul 21 '06 #3

P: n/a
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

Jul 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.