On Fri, May 29, 2020 at 5:54 AM <tritium-l...@sdamon.com> wrote: > > > -----Original Message----- > > From: Chris Angelico <ros...@gmail.com> > > > > People can already put all their main logic into a function. If you want > to unit- > > test your main function, that's the best way to do it. > > The trouble is, how much goes into main() and how much into if __name__ > > == '__main__'? For example: Does your main function accept a list of > > arguments, or does it look in sys.argv? Neither answer is wrong. And that > > means the best way is to NOT force everyone across all of Python to choose > > the same way - let people write their code their way. > > > > People write main entry points that are not exactly this? > > If __name__ == '__main__': > sys.exit(main(sys.argv[1:])) >
Of course they do! Much more common in my code is this: if __name__ == "__main__": main() or some variation that fetches sys.argv but doesn't call sys.exit. And quite a number of my projects include a global try/except around main() to log errors to a file as well as to stderr (due to where they're used), or process their args individually (for arg in sys.argv[1:]: do_stuff(arg)), or some other variation. It's most certainly NOT always exactly what you show there. And that's the problem. If it's part of the language definition, it will always have *exactly* the same semantics. As an idiom, it can be varied slightly to suit the situation, but as a language feature, it's rigid. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@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/ITRCOHH525FPD5IQL7AWUY67IBBTGCLD/ Code of Conduct: http://python.org/psf/codeofconduct/