title: Python passing callback function in a class
body: <p>I have to try to move from the non-class-based coding style into class-based coding style, but facing an issue. The optimize() function takes a callback function mycallback(). The code works perfectly fine in Non-class-based method, but when I moved it to class-based method, I got an error "mycallback() takes exactly 3 arguments (1 given)". </p>
  
  <p>What is the right way to pass a callback function in the class-based method? </p>
  
  <p>(A) Non-class-based method:</p>
  
  <pre><code>def mycallback(model, where):
      pass
  
  model = Model()
  model.optimize(mycallback)
  </code></pre>
  
  <p>(B) Class-based method:</p>
  
  <pre><code>class A:
      def __init__(self):
          self.model = Model()
  
      def solve(self):
          # Try method 1:
          self.model.optimize(self.mycallback())      &lt;--- Error: mycallback() takes exactly 3 arguments (1 given)
          # Try method 2:
          # self.model.optimize(self.mycallback)  &lt;--- Error:  Callback argument must be a function
  
      def mycallback(self, model, where):     
          pass
  </code></pre>
  
  <p>While this is a problem regarding passing a callback function to Gurobi's (an optimization solver） built-in function, I believe it is a more general question on how to pass a callback function defined in a class to another function in Python. </p>
  
  <hr>
  
  <p>Error For method 2:</p>
  
  <pre><code>   self.model.optimize(self.mycallback)  
     File "model.pxi", line 458, in gurobipy.Model.optimize      (../../src/python/gurobipy.c:34263)
     gurobipy.GurobiError: Callback argument must be a function
  </code></pre>
  
  <p>Looks like it is likely to be Gurobi API issue. Wonder if any Gurobi dev will response.</p>