本文整理汇总了Python中IPython.terminal.embed.InteractiveShellEmbed.excepthook方法的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShellEmbed.excepthook方法的具体用法?Python InteractiveShellEmbed.excepthook怎么用?Python InteractiveShellEmbed.excepthook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.terminal.embed.InteractiveShellEmbed
的用法示例。
在下文中一共展示了InteractiveShellEmbed.excepthook方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cmd_shell
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import excepthook [as 别名]
def cmd_shell(self):
# readline is used transparently by code.InteractiveConsole()
import readline # noqa: F401
vars = {
'concurrency_groups': self.config.concurrency_groups,
'config': self.config,
'datetime': datetime,
'db': self.db,
'dsari': dsari,
'jobs': self.config.jobs,
}
banner = 'Additional variables available:\n'
for (k, v) in vars.items():
v = vars[k]
if type(v) == dict:
r = 'Dictionary ({} items)'.format(len(v))
elif type(v) == list:
r = 'List ({} items)'.format(len(v))
else:
r = repr(v)
banner += ' {}: {}\n'.format(k, r)
banner += '\n'
sh = None
try:
from IPython.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed(user_ns=vars, banner2=banner)
sh.excepthook = sys.__excepthook__
except ImportError:
print('ipython not available. Using normal python shell.')
if sh:
sh()
else:
import code
class DsariConsole(code.InteractiveConsole):
pass
console_vars = vars.copy().update({
'__name__': '__console__',
'__doc__': None,
})
print(banner, end='')
DsariConsole(locals=console_vars).interact()