title: Step-by-step debugging with IPython
body: <p>From what I have read, there are two ways to debug code in Python:</p>
  <ul>
  <li><p>With a traditional debugger such as <code>pdb</code> or <code>ipdb</code>. This supports commands such as <code>c</code> for <code>continue</code>, <code>n</code> for <code>step-over</code>, <code>s</code> for <code>step-into</code> etc.), but you don't have direct access to an IPython shell which can be extremely useful for object inspection.</p>
  </li>
  <li><p>Using  <strong>IPython</strong> by <a href="http://ipython.org/ipython-doc/dev/interactive/reference.html#embedding-ipython" rel="noreferrer">embedding</a> an IPython shell in your code. You can do <code>from IPython import embed</code>, and then use <code>embed()</code> in your code. When your program/script hits an <code>embed()</code> statement, you are dropped into an IPython shell. This allows the full inspection of objects and testing of Python code using all the IPython goodies. However, when using <code>embed()</code> you can't <strong>step-by-step</strong> through the code anymore with handy keyboard shortcuts.</p>
  </li>
  </ul>
  <p>Is there any way to combine the best of both worlds? I.e.</p>
  <ol>
  <li>Be able to  <strong>step-by-step</strong> through your code with handy pdb/ipdb keyboard shortcuts.</li>
  <li>At any such step (e.g. on a given statement), have access to a full-fledged <strong>IPython shell</strong>.</li>
  </ol>
  <h3>IPython debugging <em>as in</em> MATLAB:</h3>
  <p>An example of this type of &quot;enhanced debugging&quot; can be found  in MATLAB, where the user <strong>always</strong> has full access to the MATLAB engine/shell, and she can still <strong>step-by-step</strong> through her code, define conditional breakpoints, etc. From what I have discussed with other users, this is the debugging feature that people miss the most when moving from MATLAB to IPython.</p>
  <h3>IPython debugging in Emacs and other editors:</h3>
  <p>I don't want to make the question too specific, but I work mostly in Emacs, so I wonder if there is any way to bring this functionality into it. <strong>Ideally</strong>, Emacs (or the editor) would allow the programmer to set breakpoints anywhere on the code and communicate with the interpreter or debugger to have it stop in the location of your choice, and bring to a full IPython interpreter on that location.</p>