Skip to content

Instantly share code, notes, and snippets.

@travishen
Created May 16, 2022 07:29
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 travishen/23e77251821d5bc5ab29d51baa7d41d3 to your computer and use it in GitHub Desktop.
Save travishen/23e77251821d5bc5ab29d51baa7d41d3 to your computer and use it in GitHub Desktop.
def quantity(storage_name):
def getter(instance):
return instance.__dict__[storage_name]
def setter(instance, value):
if value > 0:
instance.__dict__[stoage_name] = value
raise ValueError()
return property(getter, setter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment