本文整理汇总了Python中IPython.terminal.interactiveshell.TerminalInteractiveShell.ask_exit方法的典型用法代码示例。如果您正苦于以下问题:Python TerminalInteractiveShell.ask_exit方法的具体用法?Python TerminalInteractiveShell.ask_exit怎么用?Python TerminalInteractiveShell.ask_exit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.terminal.interactiveshell.TerminalInteractiveShell
的用法示例。
在下文中一共展示了TerminalInteractiveShell.ask_exit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_python_console
# 需要导入模块: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
# 或者: from IPython.terminal.interactiveshell.TerminalInteractiveShell import ask_exit [as 别名]
def get_python_console(namespace=None):
"""
Return a interactive python console instance with caller's stack
"""
if namespace is None:
import inspect
frame = inspect.currentframe()
caller = frame.f_back
if not caller:
logging.error("can't find caller who start this console.")
caller = frame
namespace = dict(caller.f_globals)
namespace.update(caller.f_locals)
try:
from IPython.terminal.interactiveshell import TerminalInteractiveShell
shell = TerminalInteractiveShell(user_ns=namespace)
except ImportError:
try:
import readline
import rlcompleter
readline.set_completer(rlcompleter.Completer(namespace).complete)
readline.parse_and_bind("tab: complete")
except ImportError:
pass
import code
shell = code.InteractiveConsole(namespace)
shell._quit = False
def exit():
shell._quit = True
def readfunc(prompt=""):
if shell._quit:
raise EOFError
return six.moves.input(prompt)
# inject exit method
shell.ask_exit = exit
shell.raw_input = readfunc
return shell