How do I call setattr() on the current module?
Posted
by Matt Joiner
on Stack Overflow
See other posts from Stack Overflow
or by Matt Joiner
Published on 2010-05-29T02:07:22Z
Indexed on
2010/05/29
2:12 UTC
Read the original article
Hit count: 313
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.
© Stack Overflow or respective owner