[EMAIL PROTECTED] wrote:
> I have a newby type question on how global variables work between
> modules.
>
> I have a module test2.py that defines a global variable as well as
two
> functions to operate on that variable. A script test1.py imports the
> three names and prints out values of the glob
Brian van den Broek <[EMAIL PROTECTED]> wrote:
> I'm quite fond of the
>
> import really_long_module_name as rlmn
...
> I don't think the relevant section of Nutshell mentions this idiom.
> However, I don't have my copy with me (seasonal travel, and all), so
> apologies if my memory leads me
Alex Martelli said unto the world upon 2004-12-24 03:23:
<[EMAIL PROTECTED]> wrote:
If you really must, consider using a container object. The most
suitable container object for these tasks is often a module. I.e.,
code, in test1:
import test2
and then refer to test2.glbl throughout. I.e., forg
Thank you to both of you for your assistance.
Using the qualified 'test2.glbl' form of the variable name gives the
result I need. The concepts of binding and rebinding, as programming
concerns, are new to me; I will have to study that further.
Thank you again, and Merry Christmas.
David
--
h
<[EMAIL PROTECTED]> wrote:
...
> and here is the test script, test1.py
> -
>
> from test2 import glbl, inc_glbl, get_glbl
Think of this as roughly equivalent to:
import locl
glbl = test2.glbl
and so on. That is, after the 'from test2 import', the two name
Add these lines to test1.py and see what you get:
import test2
print 'test2.glbl postinc ', test2.glbl
This will work as you expect.
Next try chaning glbl in test2 to a list (a mutable type).
test2.py:
glbl = [25]
def inc_glbl():
global glbl
glbl[0] = glbl[0] + 1
def get_glb
I have a newby type question on how global variables work between
modules.
I have a module test2.py that defines a global variable as well as two
functions to operate on that variable. A script test1.py imports the
three names and prints out values of the global between operations, and
the resul