1
"""Quick code snippets for embedding IPython into other programs.
3
See example-embed.py for full details, this file has the bare minimum code for
4
cut and paste use once you understand how to use the system."""
6
#---------------------------------------------------------------------------
7
# This code loads IPython but modifies a few things if it detects it's running
8
# embedded in another IPython session (helps avoid confusion)
14
banner = exit_msg = ''
16
# Command-line options for IPython (a list like sys.argv)
17
argv = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:']
18
banner = '*** Nested interpreter ***'
19
exit_msg = '*** Back in main IPython ***'
21
# First import the embeddable shell class
22
from IPython.Shell import IPShellEmbed
23
# Now create the IPython shell instance. Put ipshell() anywhere in your code
24
# where you want it to open.
25
ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg)
27
#---------------------------------------------------------------------------
28
# This code will load an embeddable IPython shell always with no changes for
31
from IPython.Shell import IPShellEmbed
32
ipshell = IPShellEmbed()
33
# Now ipshell() will open IPython anywhere in the code.
35
#---------------------------------------------------------------------------
36
# This code loads an embeddable shell only if NOT running inside
37
# IPython. Inside IPython, the embeddable shell variable ipshell is just a
43
from IPython.Shell import IPShellEmbed
44
ipshell = IPShellEmbed()
45
# Now ipshell() will open IPython anywhere in the code
47
# Define a dummy ipshell() so the same code doesn't crash inside an
51
#******************* End of file <example-embed-short.py> ********************