title: How to use code from external Python files in Jupyter notebook?
body: <p>I have a pet project which I started as a Jupyter notebook. So far, I put all the Python code in the notebook.</p>
  
  <p>At the start everything was fine. But over time the code I wrote in the notebook became more and more complex. Now it is close to unmanagenable: When I find an error, I need</p>
  
  <ol>
  <li>to navigate to the code part with the error (usually at the beginning of the notebook),</li>
  <li>fix the error there,</li>
  <li>go to (usually) the bottom of the notebook to trigger the execution of the code I changed.</li>
  </ol>
  
  <p>I want to separate the code in two parts:</p>
  
  <ol>
  <li>One that will be stored as Python files and which I will edit using an editor (and/or an IDE).</li>
  <li>The code in the Jupyter notebook that calls code parts 1 and presents its output (i. e. use the Jupyter notebook as a user interface for the Python code from step 1).</li>
  </ol>
  
  <p>Let's assume that the notebook runs on my local machine (Windows 7; Jupyter runs in Anaconda) and the Python files are also stored locally.</p>
  
  <p>What are good ways to use code from IPython files such that I can modify this code frequently and fast?</p>
  
  <p>By "frequently and fast" I mean "with as little steps as possible that are necessary to propagate changes from Python files to the notebook". The ideal solution would be something where I change one of the Python files, run one command, and then the changes are available in the Jupyter notebook. Or, to use an older analogy, I want it to be like PHP -- you change the code often and immediately see the results of your changes.</p>
  
  <p><strong>Update 1:</strong> I tried to use the solution with <code>%load TestClass.py</code> in a cell.</p>
  
  <p>The problem is that the cell contents is not updated, if the file changes.</p>
  
  <p>Example:</p>
  
  <p>Let's say I put the text </p>
  
  <pre><code>class TestClass:
      def __init__(self):
          print("TestClass constructor")
  </code></pre>
  
  <p>into <code>TestClass.py</code>. Then I create a cell in Jupyter notebook with <code>%load TestClass.py</code>. When I execute that cell, the code from <code>TestClass.py</code> is imported and the line <code>%load TestClass.py</code> gets commented out.</p>
  
  <p>Now I change <code>TestClass.py</code> to</p>
  
  <pre><code>class TestClass:
      def __init__(self):
          print("TestClass constructor")
          print("change")
  </code></pre>
  
  <p>When I execute the cell, its contents has not changed.</p>