Guest User

Untitled

a guest
Oct 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class Descriptor:
  2.  
  3. def __init__(self, obj):
  4. self.obj = obj
  5.  
  6. def __get__(self, instance, owner=None):
  7. print('Acessando o __get__')
  8. return self.obj
  9.  
  10.  
  11. class Grok:
  12.  
  13. attr = Descriptor('value')
  14.  
  15. # Output
  16. >>> g = Grok()
  17. >>> g.attr
  18. Acessando o __get__
  19. value
  20.  
  21. class Grok:
  22.  
  23. def __init__(self, attr):
  24. self.attr = Descriptor(attr)
  25.  
  26.  
  27. # Output
  28. >>> g = Grok('value')
  29. >>> g.attr
  30. <__main__.Descriptor at 0x7fe5bca77550>
Add Comment
Please, Sign In to add comment