title: Ipython Notebook: programmatically read and execute cells
body: <p>In the ipython notebook, I would like to programmatically read and execute code cells from within a code cell itself.</p>
  
  <p>Something like</p>
  
  <pre><code>if condition:
    # run input cell no. 3
  </code></pre>
  
  <p>I found a solution <a href="http://nbviewer.ipython.org/gist/minrk/5491090/analysis.ipynb" rel="nofollow noreferrer">here</a>, the function <code>execute_notebook</code> reads an <code>ipynb</code> file cell by cell and executes code cells using <code>get_ipython().run_cell()</code>.</p>
  
  <p>Is there a way to do the same, i.e. without reading the cells from the an external <code>ipynb</code> file first? Is there a way to write macros, to reference and access code cells from within an ipython notebook?</p>