當前位置: 首頁>>代碼示例>>Python>>正文


Python interactiveshell.TerminalInteractiveShell方法代碼示例

本文整理匯總了Python中IPython.terminal.interactiveshell.TerminalInteractiveShell方法的典型用法代碼示例。如果您正苦於以下問題:Python interactiveshell.TerminalInteractiveShell方法的具體用法?Python interactiveshell.TerminalInteractiveShell怎麽用?Python interactiveshell.TerminalInteractiveShell使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在IPython.terminal.interactiveshell的用法示例。


在下文中一共展示了interactiveshell.TerminalInteractiveShell方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ipython_shell

# 需要導入模塊: from IPython.terminal import interactiveshell [as 別名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 別名]
def ipython_shell(user_ns):
    from IPython.terminal.ipapp import TerminalIPythonApp
    from IPython.terminal.interactiveshell import TerminalInteractiveShell

    class MyIPythonApp(TerminalIPythonApp):

        def init_shell(self):
            self.shell = TerminalInteractiveShell(
                prompts_class=MyPrompt, highlighting_style='emacs',
                display_banner=False, profile_dir=self.profile_dir,
                ipython_dir=self.ipython_dir, banner1=get_banner(), banner2='')
            self.shell.configurables.append(self)

    app = MyIPythonApp.instance()
    app.initialize()
    app.shell.user_ns.update(user_ns)
    sys.exit(app.start()) 
開發者ID:dongweiming,項目名稱:web_develop,代碼行數:19,代碼來源:shell.py

示例2: embed

# 需要導入模塊: from IPython.terminal import interactiveshell [as 別名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 別名]
def embed(**kwargs):
    """Call this to embed IPython at the current point in your program.

    The first invocation of this will create an :class:`InteractiveShellEmbed`
    instance and then call it.  Consecutive calls just call the already
    created instance.

    If you don't want the kernel to initialize the namespace
    from the scope of the surrounding function,
    and/or you want to load full IPython configuration,
    you probably want `IPython.start_ipython()` instead.

    Here is a simple example::

        from IPython import embed
        a = 10
        b = 20
        embed('First time')
        c = 30
        d = 40
        embed

    Full customization can be done by passing a :class:`Config` in as the
    config argument.
    """
    config = kwargs.get('config')
    header = kwargs.pop('header', u'')
    compile_flags = kwargs.pop('compile_flags', None)
    if config is None:
        config = load_default_config()
        config.InteractiveShellEmbed = config.TerminalInteractiveShell
        kwargs['config'] = config
    shell = InteractiveShellEmbed.instance(**kwargs)
    shell(header=header, stack_depth=2, compile_flags=compile_flags) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:36,代碼來源:embed.py

示例3: init_alias

# 需要導入模塊: from IPython.terminal import interactiveshell [as 別名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 別名]
def init_alias(self):
        # InteractiveShell defines alias's we want, but TerminalInteractiveShell defines
        # ones we don't. So don't use super and instead go right to InteractiveShell
        InteractiveShell.init_alias(self)

    #-------------------------------------------------------------------------
    # Things related to exiting
    #------------------------------------------------------------------------- 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:10,代碼來源:pydev_ipython_console_011.py

示例4: main

# 需要導入模塊: from IPython.terminal import interactiveshell [as 別名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 別名]
def main():
    url = sys.argv[1]
    context['url'] = url
    pkg = app.dispatch_url(url)
    context['pkg'] = pkg
    for item in pkg.to_dict().items():
        print '{} = {}'.format(*item)

    def prepare_readline():
        import os
        import readline
        import atexit

        readline.parse_and_bind('tab: complete')
        histfile = os.path.expanduser("~/.daenerys_history")

        try:
            readline.read_history_file(histfile)
        except IOError:
            pass

        def savehist(histfile):
            readline.write_history_file(histfile)

        atexit.register(savehist, histfile)
        del atexit

    try:
        from IPython.terminal.interactiveshell import TerminalInteractiveShell
        shell = TerminalInteractiveShell(user_ns=context)
        shell.mainloop()
    except ImportError:
        import code
        shell = code.InteractiveConsole(locals=context)
        shell.runcode(prepare_readline.__code__)
        shell.interact() 
開發者ID:dongweiming,項目名稱:daenerys,代碼行數:38,代碼來源:scaffold.py

示例5: test_ipython_console

# 需要導入模塊: from IPython.terminal import interactiveshell [as 別名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 別名]
def test_ipython_console(qtbot):
    """Test mock-creating a console from within ipython."""

    def mock_get_ipython():
        return TerminalInteractiveShell()

    with mock.patch(
        'napari._qt.qt_console.get_ipython', side_effect=mock_get_ipython
    ):
        console = QtConsole()
        qtbot.addWidget(console)
        assert console.kernel_client is None 
開發者ID:napari,項目名稱:napari,代碼行數:14,代碼來源:test_qt_console.py

示例6: get_python_console

# 需要導入模塊: from IPython.terminal import interactiveshell [as 別名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [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 
開發者ID:binux,項目名稱:pyspider,代碼行數:45,代碼來源:utils.py

示例7: interactive

# 需要導入模塊: from IPython.terminal import interactiveshell [as 別名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 別名]
def interactive(port=None, InterfaceClass=CanInterface, intro='', load_filename=None, can_baud=None):
    global c
    import atexit

    c = InterfaceClass(port=port, load_filename=load_filename)
    atexit.register(cleanupInteractiveAtExit)

    if load_filename is None:
        if can_baud != None:
            c.setCanBaud(can_baud)
        else:
            c.setCanBaud(CAN_500KBPS)

    gbls = globals()
    lcls = locals()

    try:
        import IPython.Shell
        ipsh = IPython.Shell.IPShell(argv=[''], user_ns=lcls, user_global_ns=gbls)
        print intro
        ipsh.mainloop(intro)

    except ImportError, e:
        try:
            from IPython.terminal.interactiveshell import TerminalInteractiveShell
            from IPython.terminal.ipapp import load_default_config
            ipsh = TerminalInteractiveShell(config=load_default_config())
            ipsh.user_global_ns.update(gbls)
            ipsh.user_global_ns.update(lcls)
            ipsh.autocall = 2       # don't require parenthesis around *everything*.  be smart!
            ipsh.mainloop(intro)
        except ImportError, e:
            try:
                from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
                ipsh = TerminalInteractiveShell()
                ipsh.user_global_ns.update(gbls)
                ipsh.user_global_ns.update(lcls)
                ipsh.autocall = 2       # don't require parenthesis around *everything*.  be smart!
                ipsh.mainloop(intro)
            except ImportError, e:
                print e
                shell = code.InteractiveConsole(gbls)
                shell.interact(intro) 
開發者ID:atlas0fd00m,項目名稱:CanCat,代碼行數:45,代碼來源:__init__.py


注:本文中的IPython.terminal.interactiveshell.TerminalInteractiveShell方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。