Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may want to explore the notion of <a href="http://docs.python.org/reference/datamodel.html" rel="noreferrer">namespaces</a>. In Python, the <a href="http://docs.python.org/tutorial/modules.html" rel="noreferrer">module</a> is the natural place for <em>global</em> data:</p> <blockquote> <p>Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. Thus, the author of a module can use global variables in the module without worrying about accidental clashes with a user’s global variables. On the other hand, if you know what you are doing you can touch a module’s global variables with the same notation used to refer to its functions, <code>modname.itemname</code>.</p> </blockquote> <p>A specific use of global-in-a-module is described here - <a href="http://effbot.org/pyfaq/how-do-i-share-global-variables-across-modules.htm" rel="noreferrer">how-do-i-share-global-variables-across-modules</a>, and for completeness the contents are shared here:</p> <blockquote> <p>The canonical way to share information across modules within a single program is to create a special configuration module (often called config or cfg). Just import the configuration module in all modules of your application; the module then becomes available as a global name. Because there is only one instance of each module, any changes made to the module object get reflected everywhere. For example:</p> <p>File: config.py</p> </blockquote> <pre><code>x = 0 # Default value of the 'x' configuration setting </code></pre> <blockquote> <p>File: mod.py</p> </blockquote> <pre><code>import config config.x = 1 </code></pre> <blockquote> <p>File: main.py</p> </blockquote> <pre><code>import config import mod print config.x </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload