global variable confusion

Robert D.M. Smith robert.dm.smith at gmail.com
Tue Feb 3 01:25:41 EST 2009


I have a question on global variables and how to use them.  I have 2 files;
a.py & b.py

# a.py -----

myvar = { 'test' : '123' }

# -------
# b.py -----

from a import myvar

def test():
     a.myvar = { 'blah' : '456' }

# -----

If I *'import a*' & type *'a.myvar'* it prints 'test' & '123'.

Now, if I *'import b'* & type *'b.test()'* ... does this actually change the
contents of myvar? It seems I have to do *'print b.myvar'* to see the change
but really I want to just simply do* 'print myvar'*. I want to be able to
change myvar anywhere. Please help me grasp this concept.

Thanks in advance.

-- 
  Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090202/4bd2a9c9/attachment.html>


More information about the Python-list mailing list