Skip to content

Instantly share code, notes, and snippets.

@toshok
Created June 5, 2015 00:33
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 toshok/d64141a11bf13b6f6132 to your computer and use it in GitHub Desktop.
Save toshok/d64141a11bf13b6f6132 to your computer and use it in GitHub Desktop.
class TestDescriptor(object):
def __init__(self, initval, name):
self.val = initval
self.name = name
def __get__(self, obj, objtype):
print "retrieving", self.name
return self.val
def __set__(self, obj, val):
print "updating", self.name
self.val = val
class MyClass(object):
x = TestDescriptor(10, "x")
class MySubclass(MyClass):
def __init__(self):
print super(MyClass, self).x
x = MySubclass()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment