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


Python InteractiveShell.instance方法代码示例

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


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

示例1: append_display_data

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def append_display_data(self, display_object):
        """Append a display object as an output.

        Parameters
        ----------
        display_object : IPython.core.display.DisplayObject
            The object to display (e.g., an instance of
            `IPython.display.Markdown` or `IPython.display.Image`).
        """
        fmt = InteractiveShell.instance().display_formatter.format
        data, metadata = fmt(display_object)
        self.outputs += (
            {
                'output_type': 'display_data',
                'data': data,
                'metadata': metadata
            },
        ) 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:20,代码来源:widget_output.py

示例2: save_n_explore

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def save_n_explore(folder, path):
    """ Save and explore job-folder.

        For use with ipython interactive terminal only.
    """
    from .. import is_interactive
    from ..error import interactive as ierror
    if not is_interactive:
        raise ierror('Not in interactive session.')

    from IPython.core.interactiveshell import InteractiveShell
    from ..ipython.explore import explore
    from ..ipython.savefolders import savefolders
    import pylada

    pylada.interactive.jobfolder = folder.root
    pylada.interactive.jobfolder_path = path
    shell = InteractiveShell.instance()
    savefolders(shell, path)
    explore(shell, '{0}  --file'.format(path)) 
开发者ID:pylada,项目名称:pylada-light,代码行数:22,代码来源:__init__.py

示例3: setup_class

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def setup_class(cls):
        pytest.importorskip('IPython')

        from IPython.core.interactiveshell import InteractiveShell
        cls.display_formatter = InteractiveShell.instance().display_formatter 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_printing.py

示例4: __init__

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def __init__(self, path=None):
        self.shell = InteractiveShell.instance()
        self.path = path 
开发者ID:YosefLab,项目名称:scVI,代码行数:5,代码来源:test_notebook.py

示例5: ipython2python

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def ipython2python(code):
    """Transform IPython syntax to pure Python syntax

    Parameters
    ----------

    code : str
        IPython code, to be transformed to pure Python
    """
    shell = InteractiveShell.instance()
    return shell.input_transformer_manager.transform_cell(code) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:strings.py

示例6: clear_output

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def clear_output(stdout=True, stderr=True, other=True):
    """Clear the output of the current cell receiving output.

    Optionally, each of stdout/stderr or other non-stream data (e.g. anything
    produced by display()) can be excluded from the clear event.

    By default, everything is cleared.

    Parameters
    ----------
    stdout : bool [default: True]
        Whether to clear stdout.
    stderr : bool [default: True]
        Whether to clear stderr.
    other : bool [default: True]
        Whether to clear everything else that is not stdout/stderr
        (e.g. figures,images,HTML, any result of display()).
    """
    from IPython.core.interactiveshell import InteractiveShell
    if InteractiveShell.initialized():
        InteractiveShell.instance().display_pub.clear_output(
            stdout=stdout, stderr=stderr, other=other,
        )
    else:
        from IPython.utils import io
        if stdout:
            print('\033[2K\r', file=io.stdout, end='')
            io.stdout.flush()
        if stderr:
            print('\033[2K\r', file=io.stderr, end='')
            io.stderr.flush() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:33,代码来源:display.py

示例7: get_ipython

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def get_ipython():
    """Get the global InteractiveShell instance.
    
    Returns None if no InteractiveShell instance is registered.
    """
    from IPython.core.interactiveshell import InteractiveShell
    if InteractiveShell.initialized():
        return InteractiveShell.instance() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:getipython.py

示例8: test_no_widget_view

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def test_no_widget_view():
    # ensure IPython shell is instantiated
    # otherwise display() just calls print
    shell = InteractiveShell.instance()

    with capture_output() as cap:
        w = Widget()
        display(w)

    assert cap.outputs == [], repr(cap.outputs)
    assert cap.stdout == '', repr(cap.stdout)
    assert cap.stderr == '', repr(cap.stderr) 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:14,代码来源:test_widget.py

示例9: shell

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def shell():
    from IPython.core.interactiveshell import InteractiveShell

    shell = InteractiveShell.instance()
    shell.magic("load_ext pylada")

    return shell 
开发者ID:pylada,项目名称:pylada-light,代码行数:9,代码来源:conftest.py

示例10: load_notebook

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def load_notebook(fullname: str):
    """Import a notebook as a module."""
    shell = InteractiveShell.instance()
    path = fullname

    # load the notebook object
    with open(path, 'r', encoding='utf-8') as f:
        notebook = read(f, 4)

    # create the module and add it to sys.modules
    mod = types.ModuleType(fullname)
    mod.__file__ = path
    # mod.__loader__ = self
    mod.__dict__['get_ipython'] = get_ipython
    sys.modules[fullname] = mod

    # extra work to ensure that magics that would affect the user_ns
    # actually affect the notebook module's ns
    save_user_ns = shell.user_ns
    shell.user_ns = mod.__dict__

    try:
        for cell in notebook.cells:
            if cell.cell_type == 'code':
                try:
                    # only run valid python code
                    ast.parse(cell.source)
                except SyntaxError:
                    continue
                try:
                    # pylint: disable=exec-used
                    exec(cell.source, mod.__dict__)
                except NameError:
                    print(cell.source)
                    raise
    finally:
        shell.user_ns = save_user_ns
    return mod 
开发者ID:jwkvam,项目名称:bowtie,代码行数:40,代码来源:_magic.py

示例11: format_display_data

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def format_display_data(obj, include=None, exclude=None):
    """Return a format data dict for an object.

    By default all format types will be computed.

    The following MIME types are currently implemented:

    * text/plain
    * text/html
    * text/latex
    * application/json
    * application/javascript
    * image/png
    * image/jpeg
    * image/svg+xml

    Parameters
    ----------
    obj : object
        The Python object whose format data will be computed.

    Returns
    -------
    format_dict : dict
        A dictionary of key/value pairs, one or each format that was
        generated for the object. The keys are the format types, which
        will usually be MIME type strings and the values and JSON'able
        data structure containing the raw data for the representation in
        that format.
    include : list or tuple, optional
        A list of format type strings (MIME types) to include in the
        format data dict. If this is set *only* the format types included
        in this list will be computed.
    exclude : list or tuple, optional
        A list of format type string (MIME types) to exclue in the format
        data dict. If this is set all format types will be computed,
        except for those included in this argument.
    """
    from IPython.core.interactiveshell import InteractiveShell

    InteractiveShell.instance().display_formatter.format(
        obj,
        include,
        exclude
    ) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:47,代码来源:formatters.py

示例12: display

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def display(*objs, **kwargs):
    """Display a Python object in all frontends.

    By default all representations will be computed and sent to the frontends.
    Frontends can decide which representation is used and how.

    Parameters
    ----------
    objs : tuple of objects
        The Python objects to display.
    raw : bool, optional
        Are the objects to be displayed already mimetype-keyed dicts of raw display data,
        or Python objects that need to be formatted before display? [default: False]
    include : list or tuple, optional
        A list of format type strings (MIME types) to include in the
        format data dict. If this is set *only* the format types included
        in this list will be computed.
    exclude : list or tuple, optional
        A list of format type strings (MIME types) to exclude in the format
        data dict. If this is set all format types will be computed,
        except for those included in this argument.
    metadata : dict, optional
        A dictionary of metadata to associate with the output.
        mime-type keys in this dictionary will be associated with the individual
        representation formats, if they exist.
    """
    raw = kwargs.get('raw', False)
    include = kwargs.get('include')
    exclude = kwargs.get('exclude')
    metadata = kwargs.get('metadata')

    from IPython.core.interactiveshell import InteractiveShell

    if raw:
        for obj in objs:
            publish_display_data('display', obj, metadata)
    else:
        format = InteractiveShell.instance().display_formatter.format
        for obj in objs:
            format_dict, md_dict = format(obj, include=include, exclude=exclude)
            if metadata:
                # kwarg-specified metadata gets precedence
                _merge(md_dict, metadata)
            publish_display_data('display', format_dict, md_dict) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:46,代码来源:display.py

示例13: publish_display_data

# 需要导入模块: from IPython.core.interactiveshell import InteractiveShell [as 别名]
# 或者: from IPython.core.interactiveshell.InteractiveShell import instance [as 别名]
def publish_display_data(source, data, metadata=None):
    """Publish data and metadata to all frontends.

    See the ``display_data`` message in the messaging documentation for
    more details about this message type.

    The following MIME types are currently implemented:

    * text/plain
    * text/html
    * text/latex
    * application/json
    * application/javascript
    * image/png
    * image/jpeg
    * image/svg+xml

    Parameters
    ----------
    source : str
        A string that give the function or method that created the data,
        such as 'IPython.core.page'.
    data : dict
        A dictionary having keys that are valid MIME types (like
        'text/plain' or 'image/svg+xml') and values that are the data for
        that MIME type. The data itself must be a JSON'able data
        structure. Minimally all data should have the 'text/plain' data,
        which can be displayed by all frontends. If more than the plain
        text is given, it is up to the frontend to decide which
        representation to use.
    metadata : dict
        A dictionary for metadata related to the data. This can contain
        arbitrary key, value pairs that frontends can use to interpret
        the data. mime-type keys matching those in data can be used
        to specify metadata about particular representations.
        """
    from IPython.core.interactiveshell import InteractiveShell
    InteractiveShell.instance().display_pub.publish(
        source,
        data,
        metadata
    ) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:44,代码来源:displaypub.py


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