On Thu, 28 May 2020 09:06:36 -0000 email@example.com wrote:
In Python we often use the following syntax to call the main logic of script when it was ran: ```python def main(): pass # whatever should be done for `python ./script.py`
if __name__ == '__main__': main()
Maybe it is a time to introduce the new module level function like __main__ ?
For as long as it works (it does), there's no need to introduce anything.
However, if you want to add special features, adding __main__() can be useful. For example, for Python "strict mode" (which I hope to post for beating to this list one of these years), I need to explicitly separate "load time" from "run time" of a Python program. And to achieve that, I exactly introduce a "main" function, and even call it __main__ (so the name is taken!!111 ;-) ).
And in all fairness, all good ideas already came to somebody else years ago. There's https://www.python.org/dev/peps/pep-0299/ , successfully rejected yet back in 2002. (So, feel free to use it in your own environment/Python dialect.)