本文整理汇总了Python中IPython.nbformat.current.NotebookNode.txt方法的典型用法代码示例。如果您正苦于以下问题:Python NotebookNode.txt方法的具体用法?Python NotebookNode.txt怎么用?Python NotebookNode.txt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.nbformat.current.NotebookNode
的用法示例。
在下文中一共展示了NotebookNode.txt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_cell
# 需要导入模块: from IPython.nbformat.current import NotebookNode [as 别名]
# 或者: from IPython.nbformat.current.NotebookNode import txt [as 别名]
def run_cell(km, cell, timeout=20):
shell = km.shell_channel
iopub = km.iopub_channel
shell.execute(cell.input)
shell.get_msg(timeout=timeout)
outs = []
while True:
try:
msg = iopub.get_msg(timeout=0.2)
except Empty:
break
msg_type = msg['msg_type']
if msg_type in ('status', 'pyin'):
continue
elif msg_type == 'clear_output':
outs = []
continue
content = msg['content']
out = NotebookNode(output_type=msg_type)
if msg_type == 'stream':
out.stream = content['name']
out.txt = content['data']
elif msg_type in ('display_data', 'pyout'):
for mime, data in content['data'].items():
attr = mime.split('/')[-1].lower()
attr = attr.replace('+xml', '').replace('plain', 'text')
setattr(out, attr, data)
if msg_type == 'pyout':
out.prompt_number = content['execution_count']
elif msg_type == 'pyerr':
out.ename = content['ename']
out.evalue = content['evalue']
out.traceback = content['traceback']
else:
print("unhandled iopub msg:", msg_type)
outs.append(out)
cell.outputs = outs
return outs