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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4