##// END OF EJS Templates
Update deepreload to use a rewritten knee.py. Fixes dreload(numpy)....
Update deepreload to use a rewritten knee.py. Fixes dreload(numpy). knee.py, a Python re-implementation of hierarchical module import was removed from the standard library because it no longer functioned properly. deepreload.py is little more than a hacked version of knee.py which overrides __builtin__.__import__ to ensure that each module is re-imported once (before just referring to sys.modules as usual). In addition, `os.path` was added to the default excluded modules, since somehow it has an entry in sys.modules without `os' being a package.

File last commit:

r4125:fa42ce72
r6531:c0ad0135
Show More
example-embed-short.py
47 lines | 1.8 KiB | text/x-python | PythonLexer
/ docs / examples / core / example-embed-short.py
"""Quick code snippets for embedding IPython into other programs.
See example-embed.py for full details, this file has the bare minimum code for
cut and paste use once you understand how to use the system."""
#---------------------------------------------------------------------------
# This code loads IPython but modifies a few things if it detects it's running
# embedded in another IPython session (helps avoid confusion)
try:
get_ipython
except NameError:
banner=exit_msg=''
else:
banner = '*** Nested interpreter ***'
exit_msg = '*** Back in main IPython ***'
# First import the embed function
from IPython.frontend.terminal.embed import InteractiveShellEmbed
# Now create the IPython shell instance. Put ipshell() anywhere in your code
# where you want it to open.
ipshell = InteractiveShellEmbed(banner1=banner, exit_msg=exit_msg)
#---------------------------------------------------------------------------
# This code will load an embeddable IPython shell always with no changes for
# nested embededings.
from IPython import embed
# Now embed() will open IPython anywhere in the code.
#---------------------------------------------------------------------------
# This code loads an embeddable shell only if NOT running inside
# IPython. Inside IPython, the embeddable shell variable ipshell is just a
# dummy function.
try:
get_ipython
except NameError:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
ipshell = InteractiveShellEmbed()
# Now ipshell() will open IPython anywhere in the code
else:
# Define a dummy ipshell() so the same code doesn't crash inside an
# interactive IPython
def ipshell(): pass
#******************* End of file <example-embed-short.py> ********************