namespace question

Nugent, Pete (P.) pnugent3 at jaguar.com
Wed Apr 19 05:26:00 EDT 2006


Hi all,

I'm confused by namespaces in python, specifically using the global keyword.  I'm able to access and modify a global variable from a function if the function is defined in the same module but not if the function is defined in a different module:

//File t2.py
def sn():
    global test_var 
    test_var = 2

//File t1.py
test_var = 1
print test_var
from t2 import sn
sn()
print test_var
def so():
    global test_var 
    test_var = 3
so()
print test_var


The output from running t1 is:
1
1
3

Can anyone tell me how I can modify the test_var variable form another module?

Pete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060419/9c97a047/attachment.html>


More information about the Python-list mailing list