[Python-Dev] python-dev Summary for 2004-10-16 through 2004-10-31
[draft]
Nick Coghlan
ncoghlan at iinet.net.au
Sun Dec 12 05:10:59 CET 2004
Brett C. wrote:
> This also brought up the discussion of being able to specify a 'main'
> function to take the place of the good old ``if __name__ == "__main__"``
> idiom. Some liked the idea of allowing one to define a function named
> 'main', others '__main__'. But the discussion never went any farther.
> This will require a PEP to ever even be seriously considered.
There's a PEP already - PEP 299.
The PEP actually describes a reasonable approach, since code using the current
idiom is unlikely to define a __main__() function. However, it seems more like a
Py3K idea, since if it's only in 2.5 and later, we'd see code like this to
support earlier 2.x versions:
==========================
def __main__(*args):
...
if __name__ == "__main__":
import sys as _sys
if _sys.version_info < (2, 5):
__main__(_sys.argv)
==========================
Or, instead (using only the current idiom):
==========================
def _main(*args):
...
if __name__ == "__main__":
import sys as _sys
_main(_sys.argv)
==========================
So, to my mind, the backwards compatibility issue completely defeats the PEP's
goal of finding a cleaner idiom than the current one.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-Dev
mailing list