title: IPython: how to automagically load npz file and assign values to variables?
body: <p>I'm new to Python and I'm eagerly migrating from MATLAB to IPython as my preferred language for data analysis at the lab. </p>
  
  <p>In MATLAB, after a session of data crunching, I would do</p>
  
  <pre><code>&gt;&gt;&gt; save('myresults.mat','x','y','z');
  </code></pre>
  
  <p>and save the results of the variables x, y and z in a file called 'myresults.mat'. Later on, I could simply say:</p>
  
  <pre><code>&gt;&gt;&gt; load('myresults');
  </code></pre>
  
  <p>and MATLAB would load the .mat file AND assign the stored values of the variables to the current workspace. </p>
  
  <p>I've recently learned that I can do similarly for IPython using numpy, namely:</p>
  
  <pre><code>import numpy as np
  a = 2
  b = np.sqrt(2)
  np.savez('myresultsinpython',a,b)
  </code></pre>
  
  <p>and later do something like</p>
  
  <pre><code>npzfile = np.load('myresultsinpython')
  </code></pre>
  
  <p>However, what I get is an object from which I can access my variables by:</p>
  
  <pre><code>npzfile['arr_1']
  </code></pre>
  
  <p>etc., but I loose all info on the original names of the variables. I know I could save the file by doing</p>
  
  <pre><code>np.savez('myresultsinpython',a=a,b=b)
  </code></pre>
  
  <p>but this is not that useful, as I still have to do something like:</p>
  
  <pre><code>npzfile['a']
  </code></pre>
  
  <p>to access the variable's value. </p>
  
  <p>How do I both load the file and have the variables created in my workspace and their values assigned according to the values stored in the file?</p>
  
  <p>Something like <code>np.load('myresults')</code> and be able to do <code>a+b</code> and get <code>3.4142135623730949 (=2+sqrt(2))</code> in return.</p>