On Mon, Feb 2, 2009 at 10:25 PM, Robert D.M. Smith <robert.dm.sm...@gmail.com> wrote: > 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' }
test() will fail at runtime with a NameError. You imported only 'myvar' from 'a', not 'a' itself (i.e. there is no variable 'a' defined with 'b', only the variable 'myvar'). Assuming you changed the import to `import a`, then yes, a.myvar (both within 'a' itself and when accessed from 'b') would have its value changed by test(). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list