microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.18.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/pip/qsharp/openqasm/_ipython.py

24lines · modepreview

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

from .._native import Output  # type: ignore

_in_jupyter = False
try:
    from IPython.display import display

    if get_ipython().__class__.__name__ == "ZMQInteractiveShell":  # type: ignore
        _in_jupyter = True  # Jupyter notebook or qtconsole
except:
    pass


def display_or_print(output: Output) -> None:
    if _in_jupyter:
        try:
            display(output)
            return
        except:
            # If IPython is not available, fall back to printing the output
            pass
    print(output, flush=True)