Re: Python __main__ function

On Fri, May 29, 2020 at 5:54 AM <tritium-list@sdamon.com> wrote:
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
participants (1)
-
Chris Angelico