Created
August 4, 2017 11:19
-
-
Save kostasdizas/74d125e560923a88e6a8dd6d8363aefd to your computer and use it in GitHub Desktop.
introretrospection.py
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 Foo(object): | |
def whoami(self): | |
return [k for k,v in globals().iteritems() if v is self] | |
def whoarewe(self): | |
return [k for k,v in globals().iteritems() if isinstance(v, type(self))] | |
f = Foo() | |
b = Foo() | |
print(f.whoami()) # -> ['f'] | |
print(f.whoarewe()) # -> ['f', 'b'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment