Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import inspect
- class A:
- def caller(self):
- frames = inspect.getouterframes(inspect.currentframe())
- return inspect.getargvalues(frames[2][0]).locals.get("self")
- def bar(self):
- print self.caller()
- class B:
- def bar(self):
- A().bar()
- B().bar()
- ##################################
- <__main__.B instance at 0x004C3AA8>
Advertisement
Add Comment
Please, Sign In to add comment