本文整理汇总了Python中IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell.get_ipython方法的典型用法代码示例。如果您正苦于以下问题:Python TerminalInteractiveShell.get_ipython方法的具体用法?Python TerminalInteractiveShell.get_ipython怎么用?Python TerminalInteractiveShell.get_ipython使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell
的用法示例。
在下文中一共展示了TerminalInteractiveShell.get_ipython方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
# 或者: from IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell import get_ipython [as 别名]
def execute(file_, verbose = 0, stop_on_error = 1, store_history = 0):
""" Read and execute lines of code in given open file.
Supports pure python or ipython-bash style syntax,
multi-line code, and the IPython feature set
"""
shell = TerminalInteractiveShell()
c = shell.get_ipython()
c.instance() # initialize ipython config
raw_cells = file_.readlines()
exception = None
while raw_cells:
# Extract smallest possible executable block of code from raw source
is_completed = c.input_splitter.push(raw_cells.pop(0))
while not is_completed:
is_completed = c.input_splitter.push(raw_cells.pop(0))
cell, raw_cell = c.input_splitter.source_raw_reset()
# Transform cell into syntactically correct python
cell = c.prefilter_manager.prefilter_lines(cell) + '\n'
# If we are storing script in/out history
if store_history:
c.history_manager.store_inputs(c.execution_count,
cell, raw_cell)
# Compile to byte code
code = compile(cell, 'cellname', 'exec')
if verbose:
print '========'
print 'executing:', cell
print '========'
outflag = c.run_code(code)
if stop_on_error and outflag:
c.exit()
break