Skip to content

Instantly share code, notes, and snippets.

@luhn
Created April 14, 2012 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luhn/2381814 to your computer and use it in GitHub Desktop.
Save luhn/2381814 to your computer and use it in GitHub Desktop.
Generic Getters and Setters
class Foo(object):
def setter(var):
def set(self, value):
setattr(self, var, value+' unicorn')
return set
def getter(var):
def get(self):
return getattr(self, var)+' sasquatch'
return get
foo = property(getter('_bar'), setter('_bar'))
f = Foo()
f.foo = 'hi'
print f.foo
#Output:
#hi unicorn sasquatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment