How do I call setattr() on the current module?
What do I pass as the first parameter " object " to the function setattr(object, name, value) , to set variables on the current module? For example: setattr(object, "SOME_CONSTANT", 42); giving the same effect as: SOME_CONSTANT = 42 within the module containing these lines (with the correct object ). I'm generate several values at the module level dynamically, and as I can't define __getattr__ at the module level, this is my fallback. import sys thismodule = sys.modules[__name__] setattr(thismodule, name, value) or, without using setattr (which breaks the letter of the question but satisfies