title: How to use global variables in IPython
body: <p>How does IPython handle local variables?  I have this function that works in the Python shell but will not work in the IPython shell.</p>
  
  <pre><code>def change(key,value):
      global aname
      global alist
      alist.append(key)
      aname.extend(value)
  </code></pre>
  
  <p>I am using this inside a <code>for</code> loop and which is reading input in from a JSON and other .txt files and adding the keys and value to a list which is then used by another function to save to the database. If I do not do it this way it will be ugly and will use the indexes in my loop.</p>
  
  <pre><code>[change(key,value) for key,value in jsondata.itervalues()]
  
  def storeindatabase():
      do_sothing to the list aname and store
      do_sothing to the alist and store
  </code></pre>