I agree with Paul's sentiment. We do not need to bless just one way of writing scripts. Code review or organization style guides, sure. But not at language level. I also write scripts with no explicit __main__. But I rarely name them as .py. In the style of Unix commands, they have no extension, but have a pound-bang at the start. This has the side effect of making them much less straightforward to import at all. On Fri, May 29, 2020, 3:29 AM Paul Moore <p.f.moore@gmail.com> wrote:
Also, I routinely write scripts that have no `if __name__ == '__main__'` line at all, they just run - no-one should ever import them, so it makes no difference. And I exit (in multiple places) using `raise SystemExit("reason")`.
My point being that yes, there are *lots* of ways of writing Python scripts/programs. Why "bless" one of them as being somehow superior?
Paul
On Fri, 29 May 2020 at 02:02, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On 29/05/20 8:05 am, tritium-list@sdamon.com wrote:
People write main entry points that are not exactly this?
If __name__ == '__main__': sys.exit(main(sys.argv[1:]))
It's not clear that exiting with the return value of main() is the most Pythonic thing to do -- it's more of a C idiom that doesn't seem so useful when exceptions exist.
-- Greg _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/UEFQEB...
Code of Conduct: http://python.org/psf/codeofconduct/
Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/JMRF6P... Code of Conduct: http://python.org/psf/codeofconduct/