Skip to content

Instantly share code, notes, and snippets.

@anaved
Created July 12, 2017 22:20
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 anaved/bdf3c3703f1050c10792dde4f8003ed1 to your computer and use it in GitHub Desktop.
Save anaved/bdf3c3703f1050c10792dde4f8003ed1 to your computer and use it in GitHub Desktop.
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