Skip to content

Instantly share code, notes, and snippets.

View dluman's full-sized avatar

Douglas Luman dluman

View GitHub Profile
@cbare
cbare / dynamic_object.py
Created January 31, 2013 01:07
How to get a dynamic object in Python. A dynamic object is just a bag of properties, some of which might happen to be functions, just like objects in javascript. Forget OOP. This is QDP - quick-n-dirty programming!
class Dynamic(dict):
"""Dynamic objects are just bags of properties, some of which may happen to be functions"""
def __init__(self, **kwargs):
self.__dict__ = self
self.update(kwargs)
def __setattr__(self, name, value):
import types
if isinstance(value, types.FunctionType):
self[name] = types.MethodType(value, self)