Hello,

On Thu, 28 May 2020 09:06:36 -0000
redrad...@gmail.com wrote:

> Hi all,
> 
> 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.)

[]

-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
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/EPHA4JOFUMZS362GLHQMYFCEKMXKBV3Z/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to