Created
November 29, 2014 20:31
-
-
Save markshannon/894ec6947f26d46578f3 to your computer and use it in GitHub Desktop.
Pure Python module with dynamic attributes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
original = sys.modules[__name__] | |
class M(object): | |
__class__ = type(original) | |
#Define __str__, __repr__, etc. here | |
def __getattr__(self, name): | |
#Put code here to generate dynamic attributes | |
return name | |
replacement = M() | |
replacement.__dict__ = original.__dict__ | |
sys.modules[__name__] = replacement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment