本文整理汇总了Python中IPython.core方法的典型用法代码示例。如果您正苦于以下问题:Python IPython.core方法的具体用法?Python IPython.core怎么用?Python IPython.core使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython
的用法示例。
在下文中一共展示了IPython.core方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fix_ipython_backend2gui
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import core [as 别名]
def _fix_ipython_backend2gui(cls):
# Fix hard-coded module -> toolkit mapping in IPython (used for
# `ipython --auto`). This cannot be done at import time due to
# ordering issues, so we do it when creating a canvas, and should only
# be done once per class (hence the `lru_cache(1)`).
if "IPython" not in sys.modules:
return
import IPython
ip = IPython.get_ipython()
if not ip:
return
from IPython.core import pylabtools as pt
if (not hasattr(pt, "backend2gui")
or not hasattr(ip, "enable_matplotlib")):
# In case we ever move the patch to IPython and remove these APIs,
# don't break on our side.
return
backend_mod = sys.modules[cls.__module__]
rif = getattr(backend_mod, "required_interactive_framework", None)
backend2gui_rif = {"qt5": "qt", "qt4": "qt", "gtk3": "gtk3",
"wx": "wx", "macosx": "osx"}.get(rif)
if backend2gui_rif:
if _is_non_interactive_terminal_ipython(ip):
ip.enable_gui(backend2gui_rif)
示例2: _fix_ipython_backend2gui
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import core [as 别名]
def _fix_ipython_backend2gui(cls):
# Fix hard-coded module -> toolkit mapping in IPython (used for
# `ipython --auto`). This cannot be done at import time due to
# ordering issues, so we do it when creating a canvas, and should only
# be done once per class (hence the `lru_cache(1)`).
if "IPython" not in sys.modules:
return
import IPython
ip = IPython.get_ipython()
if not ip:
return
from IPython.core import pylabtools as pt
if (not hasattr(pt, "backend2gui")
or not hasattr(ip, "enable_matplotlib")):
# In case we ever move the patch to IPython and remove these APIs,
# don't break on our side.
return
backend_mod = sys.modules[cls.__module__]
rif = getattr(backend_mod, "required_interactive_framework", None)
backend2gui_rif = {"qt5": "qt", "qt4": "qt", "gtk3": "gtk3",
"wx": "wx", "macosx": "osx"}.get(rif)
if backend2gui_rif:
pt.backend2gui[get_backend()] = backend2gui_rif
# Work around pylabtools.find_gui_and_backend always reading from
# rcParamsOrig.
orig_origbackend = mpl.rcParamsOrig["backend"]
try:
mpl.rcParamsOrig["backend"] = mpl.rcParams["backend"]
ip.enable_matplotlib()
finally:
mpl.rcParamsOrig["backend"] = orig_origbackend
示例3: pretty_print
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import core [as 别名]
def pretty_print(self, show_imports:bool=True, combinators:bool=True, ipython_display:Union[bool,str]=False):
"""Returns the Python source code representation of the operator.
Parameters
----------
show_imports : bool, default True
Whether to include import statements in the pretty-printed code.
combinators : bool, default True
If True, pretty-print with combinators (`>>`, `|`, `&`). Otherwise, pretty-print with functions (`make_pipeline`, `make_choice`, `make_union`) instead.
ipython_display : union type, default False
- False
Return the pretty-printed code as a plain old Python string.
- True:
Pretty-print in notebook cell output with syntax highlighting.
- 'input'
Create a new notebook cell with pretty-printed code as input.
Returns
-------
str or None
If called with ipython_display=False, return pretty-printed Python source code as a Python string.
"""
result = lale.pretty_print.to_string(self, show_imports, combinators, call_depth=2)
if ipython_display == False:
return result
elif ipython_display == 'input':
import IPython.core
ipython = IPython.core.getipython.get_ipython()
comment = "# generated by pretty_print(ipython_display='input') from previous cell\n"
ipython.set_next_input(comment+result, replace=False)
else:
assert ipython_display in [True, 'output']
import IPython.display
markdown = IPython.display.Markdown(f'```python\n{result}\n```')
return IPython.display.display(markdown)