fork download
  1. class Idade(object):
  2. def __init__(self, value=None):
  3. self.value = value
  4.  
  5. def __get__(self, obj, objtype):
  6. return self.value
  7.  
  8. def __set__(self, obj, val):
  9. if val < 0:
  10. raise ValueError
  11. self.value = val
  12.  
  13. class Pessoa(object):
  14. idade = Idade(30)
  15.  
  16. m = Pessoa()
  17. m.idade = -3
Runtime error #stdin #stdout #stderr 0.04s 9408KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 17, in <module>
  File "./prog.py", line 10, in __set__
ValueError