Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Descriptor:
- def __init__(self, obj):
- self.obj = obj
- def __get__(self, instance, owner=None):
- print('Acessando o __get__')
- return self.obj
- class Grok:
- attr = Descriptor('value')
- # Output
- >>> g = Grok()
- >>> g.attr
- Acessando o __get__
- value
- class Grok:
- def __init__(self, attr):
- self.attr = Descriptor(attr)
- # Output
- >>> g = Grok('value')
- >>> g.attr
- <__main__.Descriptor at 0x7fe5bca77550>
Add Comment
Please, Sign In to add comment