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 IPython shell?
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()
Compared to Python, IPython (created by Fernando Perez in 2001) can do every thing what python can do. Ipython provides even extra features like tab-completion, testing, debugging, system calls and many other features. You can think IPython as a powerful interface to the Python language.
The goal of IPython is to create a comprehensive environment for interactive and exploratory computing. To support this goal, IPython has three main components: An enhanced interactive Python shell.
The IPython console is now deprecated and if you want to start it, you'll need to use the Jupyter Console, which is a terminal-based console frontend for Jupyter kernels.
The answer by f3lix is no longer valid it seems, I was able to find this however:
At the top of your python script:
from IPython import embed
Wherever you want to spin up a console:
embed()
Embedding IPython might be interesting for you.
Mininum of code to run IPython in your app:
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell() # this call anywhere in your program will start IPython
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With