title: Python Listener Method with "self"
body: <p>All of the listener implementation examples I can find use listener methods without <code>self</code>, which seems to be unhelpful if you want to do something with the response outside of the passed listener method.</p>
  
  <p>Here is what I am trying:</p>
  
  <pre><code>class A:
      @property
      def command(self):
          return self._command
  
      @command.setter
      def command(self, command):
          self._command = command
          self._notify_command_observers(command)
  
      _command_callbacks = []
      def _notify_command_observers(self, command):
          for callback in self._command_callbacks:
              callback(command) #&lt;-- TypeError: function takes 2 positional arguments but 1 were given
  
      def register_command_callback(self, callback):
          self._command_callbacks.append(callback)
  
      def receive_command(self, new_command):
          self.command = new_command #&lt;-- an external process will provide this "new_command" variable
  </code></pre>
  
  <pre><code>class B:
      def use_command(self, command):
          print(command)
  
      def command_listener(self, command):
          self.use_command(command)
  
      a = A()
      a.register_command_callback(command_listener)
  </code></pre>
  
  <p>This results in the error shown in the comment above.</p>
  
  <p>If I use <code>self</code> in calling <code>callback()</code> inside <code>_notify_command_observers</code>, the wrong context is passed and <code>use_command()</code> will not be found.</p>
  
  <p>Of course I could remove <code>self</code> in <code>command_listener()</code>, but I need to access other methods and variables in the <code>class B</code> instance.</p>
  
  <p>TL;DR: How do I pass a listener method to a class instance and include the context of the passing class in that listener?</p>
  
  <p>---------- EDIT ----------</p>
  
  <p>Using @jasonharper's suggestion, this works:</p>
  
  <pre><code>class B:
      def __init__(self):
          self.a = A()
          self.a.register_command_callback(self.command_listener)
  
      def use_command(self, command):
          print(command)
  
      def command_listener(self, command):
          self.use_command(command)
  </code></pre>