Skip to content

Instantly share code, notes, and snippets.

@markshannon
Created November 29, 2014 20:31
Show Gist options
  • Save markshannon/894ec6947f26d46578f3 to your computer and use it in GitHub Desktop.
Save markshannon/894ec6947f26d46578f3 to your computer and use it in GitHub Desktop.
Pure Python module with dynamic attributes.
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