title: How to reload my Python source file, when interactively interpreting it with "python -i"
body: <p>When writing or debugging a Python program, I really like using the <code>-i</code> command line switch to be able to directly inspect my functions without having to run everything from start to finish.</p>
  
  <p>However, whenever I make a change to the code I have to close and restart my interactive session, losing all temporary variables that I might have defined. <strong>How do I reload my source file from within the python interpreter?</strong></p>
  
  <hr>
  
  <p>The builtin function <code>reload</code> looks like it was made for this, but I can only use it with named modules:</p>
  
  <pre><code>&gt;&gt; import my_prog
  &gt;&gt; print my_prog.x
  -- prints an error, because x is not defined --
  
  -- edited my_prog.py to add the x global now...
  &gt;&gt; reload(my_prog)
  &gt;&gt; print my_prog.x
  -- prints x
  </code></pre>
  
  <p>However, if I instead to do a <code>from my_prog import *</code> in the beginning reload doesn't work, and doing the import again also has no effect.</p>