Created
July 12, 2017 22:20
-
-
Save anaved/bdf3c3703f1050c10792dde4f8003ed1 to your computer and use it in GitHub Desktop.
This file contains 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 MyPropertyValidation(object): | |
def __init__(self): | |
self.__age = None | |
@property | |
def age(self): | |
if not self.__age: | |
raise ValueError("Age is None and needs to be set first.") | |
return self.__age | |
@age.setter | |
def age(self, val): | |
if isinstance( val, int ) and val > 0: | |
self.__age = val | |
else: | |
raise ValueError("Age needs to be an integer and greater than zero") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment