title: Python: Pass extra arguments to callable
body: <p>I have the following python code:</p>
  
  <pre class="lang-py prettyprint-override"><code>import networkx as nx 
  
  def cost(i, j, d, value1, value2):
      # some operation involving all these values
      return cost
  
  
  # graph is a networkx graph
  # src, dst are integers
  # cost is a callable that is passed 3 values automatically i.e. src, dst and d 
  # d is a dictionary of edge weights
  path = nx.dijkstra_path(graph, src, dst, weight=cost)
  </code></pre>
  
  <p>Now I want to pass two values <code>value1</code> and <code>value2</code> to the <code>cost</code> function.</p>
  
  <p>The <code>networkx</code> documentation says the <code>weight</code> can be a callable that accepts exactly 3 arguments. But i need <code>value1</code> and <code>value2</code> for calculations. How can this be done?</p>
  
  <p><strong>Edit</strong>
  The solution using functools works well. However, my function is in a class as follows:</p>
  
  <pre><code>import networkx as nx 
  import functools
  class Myclass:
      def cost(self, i, j, d, value2):
          # some operation involving all these values
          # also need self
  
  
      # graph is a networkx graph
      # src, dst are integers
      # cost is a callable that is passed 3 values automatically i.e. src, dst and d 
      # d is a dictionary of edge weights
      # path = nx.dijkstra_path(graph, src, dst, cost)
      cost_partial = functools.partial(cost, self=self, value2=5)
      path = nx.dijkstra_path(graph, src, dst, cost_partial)
  </code></pre>
  
  <p>Using this approach, <code>nx.dijkstra_path</code> insists upon assigning <code>src</code> to <code>self</code>. Thus the interpreter complains that <code>self</code> is assigned multiple values.
  I need self for calculating the cost.</p>