On 6/30/2025 11:53 PM, Popov, Dmitry Yu via Python-list wrote:
Dear Sirs.

I found the following sentence in the Python documentation: "The statements executed by 
the top-level invocation of the interpreter, either read from a script file or interactively, 
are considered part of a module called 
__main__<https://docs.python.org/3.11/library/__main__.html#module-__main__>, so they 
have their own global namespace."

In other words, global assignments of variables placed directly in a module's name space 
are also "statements executed by the top-level invocation of the interpreter", 
if the module is executed as a script.

Is it stable at all to assign global variables directly in a module which runs 
as a script? Speaking practically, I have not observed any problem so far.

"Global" in Python means name-spaced to its module. An assignment in a module, top-level or not, doesn't automatically become a global assignment in imported modules.

Regards,
Dmitry Popov


--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to