What is the pythonic way to setattr() for a module?

Posted by John Mulder on Stack Overflow See other posts from Stack Overflow or by John Mulder
Published on 2010-06-02T23:11:06Z Indexed on 2010/06/02 23:14 UTC
Read the original article Hit count: 128

Filed under:
|
|

In a class method, I can add attributes using the built-in function:

setattr(self, "var_name", value).  

If I want to do the same thing within a module, I can do something like:

globals()["var_name"] = value

Is this the best way to do this, or is there a more pythonic solution?

© Stack Overflow or respective owner

Related posts about python

Related posts about attributes