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


Python InteractiveShellEmbed.restore_sys_module_state方法代码示例

本文整理汇总了Python中IPython.frontend.terminal.embed.InteractiveShellEmbed.restore_sys_module_state方法的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShellEmbed.restore_sys_module_state方法的具体用法?Python InteractiveShellEmbed.restore_sys_module_state怎么用?Python InteractiveShellEmbed.restore_sys_module_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPython.frontend.terminal.embed.InteractiveShellEmbed的用法示例。


在下文中一共展示了InteractiveShellEmbed.restore_sys_module_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gnubg_InteractivePyShell_tui

# 需要导入模块: from IPython.frontend.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.frontend.terminal.embed.InteractiveShellEmbed import restore_sys_module_state [as 别名]
def gnubg_InteractivePyShell_tui(argv=[''], banner=None):
    global supports_readline
    import sys
    import traceback
    import code

    try:
        sys.argv = argv

        # Check for IPython as it is generally the best cmdline interpreter
        from IPython.frontend.terminal.embed import InteractiveShellEmbed
        from IPython import __version__ as ipyversion
        from IPython.config.loader import Config
    except:
        # Otherwise use standard interpreter
        if (banner == None):
            banner = 'Python ' + sys.version

        if (supports_readline):
            try:
                # See if we can use readline support
                import readline
            except:
                # Might be Win32 so check for pyreadline
                try:
                    import pyreadline as readline
                except:
                    pass
            try:
                # See if we can add tab completion
                import rlcompleter
                readline.parse_and_bind('tab: complete')
            except:
                pass

            try:
                code.interact(banner=banner, local=globals())
            except SystemExit:
                # Ignore calls to exit() and quit()
                pass

            return True

        else:
            # If we get this far we are on Win32 and too early
            # a version to support the embedded interpreter so
            # we simulate one
            print banner
            print '<Control-Z> and <Return> to exit'
            while True:
                print '>>> ',
                line = sys.stdin.readline()
                if not line:
                    break

                try:
                    exec(line)
                except SystemExit:
                    # Ignore calls to exit() and quit()
                    break

            return True

    try:
        # Launch IPython interpreter
        cfg = Config()
        prompt_config = cfg.PromptManager
        prompt_config.in_template = 'In <\\#> > '
        prompt_config.in2_template = '   .\\D. > '
        prompt_config.out_template = 'Out<\\#> > '
        cfg.InteractiveShell.confirm_exit = False

        if banner == None:
            banner = 'IPython ' + ipyversion + ', Python ' + sys.version

        # We want to execute in the name space of the CALLER of this function,
        # not within the namespace of THIS function.
        # This allows us to have changes made in the IPython environment
        # visible to the CALLER of this function

        # Go back one frame and get the locals.
        call_frame = sys._getframe(0).f_back
        calling_ns = call_frame.f_locals

        ipshell = InteractiveShellEmbed(
            config=cfg, user_ns=calling_ns, banner1=banner)

        try:
            ipshell()
        except SystemExit:
            # Ignore calls to exit() and quit()
            pass

        # Cleanup the sys environment (including exception handlers)
        ipshell.restore_sys_module_state()

        return True

    except:
        traceback.print_exc()
#.........这里部分代码省略.........
开发者ID:cowpig,项目名称:notorious-BG,代码行数:103,代码来源:gnubg.py


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