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   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
            http://boredomandlaziness.skystorm.net
_______________________________________________
Python-Dev mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to