
I'm going to note here that it is perfectly reasonable to use Python as a "scripting language" -- to, you know, write scripts. And when I'm writing scripts, I make heavy use of the global namespace :-) Granted, if it's really a quick and dirty script, I'll not bother with if __name__ == "__main__" at all, but there is a middle ground, where I do. There's no need to restrict Python to be more structured in this manner. -CHB On Thu, May 28, 2020 at 12:52 PM David Mertz <mertz@gnosis.cx> wrote:
On Thu, May 28, 2020, 3:06 PM Chris Angelico <rosuav@gmail.com> wrote:
There aren't multiple entry points, though. There would be multiple blocks of code that are skipped if the module is imported, but executed if it's run as a script. Remember, Python code is NOT declarative. That 'def' statement is an actual executable bit of code.
I take back my comment. I think I may have used the multiple __main__ blocks occasionally, for reasons Chris notes. Like I want something configured BEFORE a function is defined (maybe a global that only makes sense when run as script).
However, I haven't done it for a long while. I think when I was younger I didn't value encapsulation sufficiently. That said, I don't want the capability to change. There are lots of things I don't do stylistically, but I don't want striken from the language.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/FPDFDF... Code of Conduct: http://python.org/psf/codeofconduct/
-- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython