当前位置: 首页>>代码示例>>Python>>正文


Python TerminalInteractiveShell.get_ipython方法代码示例

本文整理汇总了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
开发者ID:adgaudio,项目名称:Bin,代码行数:40,代码来源:ipyscript.py


注:本文中的IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell.get_ipython方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。