title: How to access a caller method's __class__ attribute from a callee function in Python?
body: <p>Here <code>__class__</code> should not be confused with <code>self.__class__</code> which I am already able to access with the <code>inspect</code> module:</p>
  
  <pre><code>import inspect
  
  
  class A:
  
      def __init__(self):
          print(__class__.__name__)  # I want to move this statement inside f
          f()
  
  
  class B(A):
      pass
  
  
  def f():
      prev_frame = inspect.currentframe().f_back
      self = prev_frame.f_locals["self"]
      print(self.__class__.__name__)
  
  
  B()  # prints A B
  </code></pre>