Skip to content

Instantly share code, notes, and snippets.

@proger
Created February 2, 2011 13:59
Show Gist options
  • Select an option

  • Save proger/807699 to your computer and use it in GitHub Desktop.

Select an option

Save proger/807699 to your computer and use it in GitHub Desktop.
import inspect
class Y(object):
def ymethod(self, x):
x.method()
class X(object):
def method(self):
frame = inspect.currentframe()
prev = frame.f_back
caller = prev.f_locals.get('self') # hope everyone calls it 'self'
assert type(caller) == Y
print caller
Y().ymethod(X())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment