Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Positive:
- def __init__(self, attr):
- self.attr = attr # the managed attribute
- self.msg = "can't have less than zero of {}!".format(attr)
- def __set__(self, instance, value):
- if value < 0:
- raise ValueError(self.msg)
- vars(instance)[self.attr] = value
- class MelonCart:
- honeymelons = Positive('honeymelons')
- watermelons = Positive('watermelons')
- def __init__(self, honeymelons, watermelons):
- self.honeymelons = honeymelons
- self.watermelons = watermelons
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement