Skip to content

Instantly share code, notes, and snippets.

@georgeteo
Created September 14, 2015 18:22
Show Gist options
  • Save georgeteo/1fa2e237b06e239e2103 to your computer and use it in GitHub Desktop.
Save georgeteo/1fa2e237b06e239e2103 to your computer and use it in GitHub Desktop.
python class decorator example
class P:
def __init__(self,x):
self.x = x
@property
def x(self):
return self.__x
@x.setter
def x(self, x):
if x < 0:
self.__x = 0
elif x > 1000:
self.__x = 1000
else:
self.__x = x
if __name__ == "__main__":
p = P(5)
print p.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment