本文整理匯總了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