Re: Global variables and modules

2004-12-24 Thread John Machin
[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

Re: Global variables and modules

2004-12-24 Thread Alex Martelli
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

Re: Global variables and modules

2004-12-24 Thread Brian van den Broek
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

Re: Global variables and modules

2004-12-24 Thread dkeeney
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

Re: Global variables and modules

2004-12-24 Thread Alex Martelli
<[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

Re: Global variables and modules

2004-12-23 Thread Binu K S
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

Global variables and modules

2004-12-23 Thread dkeeney
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