Global Namespace

Charlie Dyson charlie at
Sun Jun 17 13:34:48 EDT 2001

This question either has a simple answer, or there is no way to do this at 
the moment. I want to be able to set a variable in the global namespace to 
a given value. Easy? What if all you have is a string containing the name 
of the variable. I need a pointer to the global namespace. So

class MyClass:
        def mymethod(self, varname, varvalue):
                setattr(pointer_to_global_namespace, varname, varvalue)

m = MyClass()
m.mymethod('var', 'ASDF')
print var # Should print 'ASDF'

Any ideas? Is there a __builtins__ funtion that provides a 
reference/pointer/whatever you call it to the global namespace.

Thanks in advance,

Charlie Dyson - charlie at

More information about the Python-list mailing list