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()
asked Jan 31, 2009 at 22:29
Mat
87.3k35 gold badges96 silver badges112 bronze badges
-
Could you please mark Dereck's answer as it is most current now?Ronan Paixão– Ronan Paixão2015年10月06日 01:36:21 +00:00Commented Oct 6, 2015 at 1:36
2 Answers 2
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()
answered Nov 10, 2013 at 16:04
Dereck Wonnacott
4931 gold badge4 silver badges7 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
answered Jan 31, 2009 at 22:35
f3lix
29.9k11 gold badges68 silver badges87 bronze badges
1 Comment
Peter Du
See below, now there is an embed function from IPython can be used instead.
lang-py