microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.23.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

source/pip/qsharp/openqasm/_ipython.py

24lines · modecode

1# Copyright (c) Microsoft Corporation.
2# Licensed under the MIT License.
3
4from .._native import Output # type: ignore
5
6_in_jupyter = False
7try:
8 from IPython.display import display
9
10 if get_ipython().__class__.__name__ == "ZMQInteractiveShell": # type: ignore
11 _in_jupyter = True # Jupyter notebook or qtconsole
12except:
13 pass
14
15
16def display_or_print(output: Output) -> None:
17 if _in_jupyter:
18 try:
19 display(output)
20 return
21 except:
22 # If IPython is not available, fall back to printing the output
23 pass
24 print(output, flush=True)
25