本文整理匯總了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