def insert_ipython(num_up=1):
"""
Placed inside a function, this will insert an IPython interpreter at that
current location. This will enabled detailed inspection of the current
execution environment, as well as (optional) modification of that environment.
*num_up* refers to how many frames of the stack get stripped off, and
defaults to 1 so that this function itself is stripped off.
"""
import IPython
from IPython.terminal.embed import InteractiveShellEmbed
try:
from traitlets.config.loader import Config
except ImportError:
from IPython.config.loader import Config
frame = inspect.stack()[num_up]
loc = frame[0].f_locals.copy()
glo = frame[0].f_globals
dd = dict(fname = frame[3], filename = frame[1],
lineno = frame[2])
cfg = Config()
cfg.InteractiveShellEmbed.local_ns = loc
cfg.InteractiveShellEmbed.global_ns = glo
IPython.embed(config=cfg, banner2 = __header % dd)
ipshell = InteractiveShellEmbed(config=cfg)
del ipshell
#
# Our progress bar types and how to get one
#
评论列表
文章目录