Created
September 14, 2015 18:22
-
-
Save georgeteo/1fa2e237b06e239e2103 to your computer and use it in GitHub Desktop.
python class decorator example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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