Skip to content

Instantly share code, notes, and snippets.

@yosisa
Created March 6, 2011 16:06
Show Gist options
  • Save yosisa/857379 to your computer and use it in GitHub Desktop.
Save yosisa/857379 to your computer and use it in GitHub Desktop.
class Foo(object):
def __init__(self, *names):
self._d = {}
for name in names:
self.add_property(name, name)
def add_property(self, name, default):
self._d[name] = default
if not hasattr(Foo, name):
setattr(Foo, name, self._add_property(name))
def _add_property(self, name):
def getter(self):
return "[[ {0} ]]".format(self._d.get(name, None))
def setter(self, value):
self._d[name] = str(value)
return property(getter, setter)
foo = Foo("foo", "bar", "baz")
print foo.foo
print foo.bar
print foo.baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment