Winand

Untitled

Jan 12th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. import inspect
  2.  
  3. class A:
  4.     def caller(self):
  5.         frames = inspect.getouterframes(inspect.currentframe())
  6.         return inspect.getargvalues(frames[2][0]).locals.get("self")
  7.        
  8.     def bar(self):
  9.         print self.caller()
  10.  
  11.    
  12. class B:
  13.     def bar(self):
  14.         A().bar()
  15.        
  16. B().bar()
  17.  
  18. ##################################
  19. <__main__.B instance at 0x004C3AA8>
Advertisement
Add Comment
Please, Sign In to add comment