Skip to content

Instantly share code, notes, and snippets.

@valdergallo
Last active December 30, 2015 05:18
Show Gist options
  • Select an option

  • Save valdergallo/7781323 to your computer and use it in GitHub Desktop.

Select an option

Save valdergallo/7781323 to your computer and use it in GitHub Desktop.
Simple exemplo de uso de descriptor com python bem legal
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