Launch an interactive shell while running Python

I wanted to do Ruby's binding.pry in Python as well.

# coding: utf-8

from IPython import embed
from IPython.terminal.embed import InteractiveShellEmbed


n = 1

print('start embed')
embed()

# === ipython interactive shell ===
#
# print(n)
# => 1
#
# n += 1
#
# Ctrl + D : exit ipython
print('end embed')


ipshell = InteractiveShellEmbed()

print('start interactive shell')
ipshell()

# === ipython interactive shell ===
#
# print(n)
# => 2
#
# Ctrl + D : exit ipython
print('end interactive shell')

It was useful information. It's short, but that's it from here.

http://ipython.org/ipython-doc/2/interactive/reference.html#embedding

Recommended Posts

Launch an interactive shell while running Python
Launch a shell while a Python script is running
python launch
How to get help in an interactive shell
Build an interactive environment for machine learning in Python