Created
June 29, 2018 05:23
-
-
Save pmuller/bd1ac430d090c94c37b37e4f48db3974 to your computer and use it in GitHub Desktop.
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 Descriptor: | |
... def __get__(self, instance, owner): | |
... print('__get__', instance, owner) | |
... print('called on a', 'class' if instance is None else 'instance') | |
... | |
>>> class Class: | |
... foo = Descriptor() | |
... | |
>>> Class.foo | |
__get__ None <class '__main__.Class'> | |
called on a class | |
>>> Class().foo | |
__get__ <__main__.Class object at 0x7f95551cf4e0> <class '__main__.Class'> | |
called on a instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment