Re: Assignment of global variables in a script.

Thomas Passin <[email protected]>
Newsgroups gmane.comp.python.general
Message-ID <[email protected]>
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
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.