title: Can I use IPython in an embedded interactive Python console?
body: <p>I use the following snippet to drop into a Python shell mid-program. This works fine, but I only get the standard console. Is there a way to do the same but using the <a href="http://ipython.scipy.org/" rel="noreferrer">IPython</a> shell?</p>
  
  <pre><code>import code
  
  class EmbeddedConsole(code.InteractiveConsole):
      def start(self):
          try:
                  self.interact("Debug console starting...")
          except:
                  print("Debug console closing...")
  
  def print_names():
      print(adam)
      print(bob)
  
  adam = "I am Adam"
  bob = "I am Bob"
  
  print_names()
  console = EmbeddedConsole(locals())
  console.start()
  print_names()
  </code></pre>