當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。