Skip to content

Instantly share code, notes, and snippets.

@kostasdizas
Created August 4, 2017 11:19
Show Gist options
  • Save kostasdizas/74d125e560923a88e6a8dd6d8363aefd to your computer and use it in GitHub Desktop.
Save kostasdizas/74d125e560923a88e6a8dd6d8363aefd to your computer and use it in GitHub Desktop.
introretrospection.py
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