01.10.21 22:35, Jonathan Crall пише:
> My motivation for writing this suggestion is in an attempt to stop a
> common anti-pattern, where instead of defining a `main` function (or a
> function by any other name) an simply calling that by adding the above
> two lines, a lot of Python users I work with will just start dumping
> their logic into the global scope of the module.

It is not an attipattern. It is how Python works (note that import, def
and class are statements executable at runtime), and it is what you
normally expect from a scripting language.

Now, sometimes you want to use the same file for two purposes: as a
module and as an executable script. You need a way to distinguish these
cases. And __name__ == "__main__" is an idiomatic way to do it in
Python. But if you do not need to mix executable and module in one file
you do not need to use it.

_______________________________________________
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/HDSLA7LEYLN33CXHEUNXHJW5R6AGDCKW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to