title: Optimal multiple return values in scientific python
body: <p>I'm using scipy/numpy for research code instead of matlab. There is one flaw, I was running into frequently. I found a work-around solution, but want to check for a <em>best practice</em> and better solution. Imagine some mathematical optimisation:</p>
  
  <pre><code>def calculation (data, max_it=10000, tol = 1e-5):
      k = 0
      rmse = np.inf 
      while k &lt; max_it and rmse &gt; tol:
          #calc and modify data - rmse becomes smaller in each iteration
          k += 1
      return data
  </code></pre>
  
  <p>It works fine, I embed it into my code, in multiple locations, e.g.:</p>
  
  <pre><code> import module
   d = module.calculation (data)
  </code></pre>
  
  <p>But sometimes I want to check further insights and need multiple return values. If I simply append multiple return values, I have to modify the other code and unpack the first return value. <strong>This is one of the few situations were I prefer matlab to scipy</strong>.In matlab only the first return value is evaluated, unless you explicitly demand the rest.</p>
  
  <p>So my work-around for matlab-like (= optimal) multiple return values are global variables [of the module]</p>
  
  <pre><code>def calculation (data, max_it=10000, tol = 1e-5):
      global k
      global rmse
      k = 0
      rmse = np.inf 
      while k &lt; max_it and rmse &gt; tol:
          #calc and modify data - rmse becomes smaller in each iteration
          k += 1
      return data
  </code></pre>
  
  <p>My function calls work without modification and if I want to verify something in ipython, Iset some variables global <em>reload(module)</em> and check the insight with <em>module.rmse</em>.</p>
  
  <p>But I could also imagine a OO-aproach from the beginning, or to use pdb, or to use other ipython magic</p>