Last active
December 30, 2015 05:18
-
-
Save valdergallo/7781323 to your computer and use it in GitHub Desktop.
Simple exemplo de uso de descriptor com python bem legal
This file contains hidden or 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 Caixa(object): | |
| def __init__(self, value=0): | |
| self.value = value | |
| def __sub__(self, value): | |
| check = self.value - value | |
| if check < 0: | |
| print "Voce nao tem saldo para isso" | |
| return | |
| self.value -= value | |
| return self.value | |
| def __add__(self, value): | |
| self.value += value | |
| return self.value | |
| def __set__(self, instance, value): | |
| if value > 0: | |
| self.value = value | |
| else: | |
| print "Voce nao pode inserir valores negativos" | |
| def __repr__(self): | |
| return repr(self.value) | |
| class Test(object): | |
| value = Caixa() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment