Created
February 2, 2011 13:59
-
-
Save proger/807699 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
| 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