本文整理匯總了Python中IPython.utils方法的典型用法代碼示例。如果您正苦於以下問題:Python IPython.utils方法的具體用法?Python IPython.utils怎麽用?Python IPython.utils使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類IPython
的用法示例。
在下文中一共展示了IPython.utils方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_security_file
# 需要導入模塊: import IPython [as 別名]
# 或者: from IPython import utils [as 別名]
def get_security_file(filename, profile='default'):
"""Return the absolute path of a security file given by filename and profile
This allows users and developers to find security files without
knowledge of the IPython directory structure. The search path
will be ['.', profile.security_dir]
Parameters
----------
filename : str
The file to be found. If it is passed as an absolute path, it will
simply be returned.
profile : str [default: 'default']
The name of the profile to search. Leaving this unspecified
The file to be found. If it is passed as an absolute path, fname will
simply be returned.
Returns
-------
Raises :exc:`IOError` if file not found or returns absolute path to file.
"""
# import here, because profiledir also imports from utils.path
from IPython.core.profiledir import ProfileDir
try:
pd = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), profile)
except Exception:
# will raise ProfileDirError if no such profile
raise IOError("Profile %r not found")
return filefind(filename, ['.', pd.security_dir])
示例2: start
# 需要導入模塊: import IPython [as 別名]
# 或者: from IPython import utils [as 別名]
def start(self) -> None:
try:
from IPython import start_ipython
from IPython.utils import io
from traitlets.config.loader import Config as IPyConfig
except ImportError:
raise ShellNotAvailableError(
"IPython shell not available " "or IPython version not supported."
)
# Hack to show custom banner
# TerminalIPythonApp/start_app doesn't allow you to customize the
# banner directly, so we write it to stdout before starting the IPython app
io.stdout.write(self.banner)
# Pass exec_lines in order to start autoreload
if self.ipy_autoreload:
if not isinstance(self.ipy_autoreload, bool):
mode = self.ipy_autoreload
else:
mode = 2
logger.debug(f"Initializing IPython autoreload in mode {mode}")
exec_lines = [
"import konch as __konch",
f"__konch.IPythonShell.init_autoreload({mode})",
]
else:
exec_lines = []
ipy_config = IPyConfig()
if self.ipy_colors:
ipy_config.TerminalInteractiveShell.colors = self.ipy_colors
if self.ipy_highlighting_style:
ipy_config.TerminalInteractiveShell.highlighting_style = (
self.ipy_highlighting_style
)
configure_ipython_prompt(ipy_config, prompt=self.prompt, output=self.output)
# Use start_ipython rather than embed so that IPython is loaded in the "normal"
# way. See https://github.com/django/django/pull/512
start_ipython(
display_banner=False,
user_ns=self.context,
config=ipy_config,
extensions=self.ipy_extensions or [],
exec_lines=exec_lines,
argv=[],
)
return None