本文整理匯總了Python中IPython.nbformat.current.NotebookNode.get方法的典型用法代碼示例。如果您正苦於以下問題:Python NotebookNode.get方法的具體用法?Python NotebookNode.get怎麽用?Python NotebookNode.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類IPython.nbformat.current.NotebookNode
的用法示例。
在下文中一共展示了NotebookNode.get方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: poll_for_msgs
# 需要導入模塊: from IPython.nbformat.current import NotebookNode [as 別名]
# 或者: from IPython.nbformat.current.NotebookNode import get [as 別名]
def poll_for_msgs(self):
"""Polls for messages from the kernel.
Used after submitting code for execution"""
try:
msg = self.iopub.get_msg(timeout=1)
if msg['msg_type'] == 'status' and msg['content']['execution_state'] == 'idle':
if _debugging: logging.info('Message -- {}:{}'.format(msg['msg_type'], msg['content']))
self._previous_status = 'IDLE'
return NotebookNode(output_type = 'IDLE')
except Empty: # state should return to idle before queue becomes empty, but we ignore it now
prevstat, self._previous_status = self._previous_status, 'EMPTY'
retstat = 'END_CELL' if prevstat == 'IDLE' else 'EMPTY'
# Assuming IDLE followed by EMPTY is the end-of-cell
return NotebookNode(output_type = retstat)
self._previous_status = '' # Not idle, that's all we are concerned about for now
content, msg_type = msg['content'], msg['msg_type']
if msg_type in ['status', 'pyin']: return NotebookNode(output_type = 'NoOp')
out = NotebookNode(output_type = msg_type)
if msg_type in ('display_data', 'pyout'):
for mime, data in content['data'].items():
try:
attr = self.MIME_MAP[mime]
tmpval = RClansiconv(data) if attr == 'text' else data
setattr(out, attr, tmpval)
except KeyError:
raise NotImplementedError('unhandled mime type: %s' % mime)
elif msg_type == 'stream':
setattr(out, 'text', RClansiconv(content['data']))
elif msg_type == 'pyerr':
setattr(out, 'html', RClansiconv('\n'.join(content['traceback']) + '\n'))
else:
if _debugging: logging.info('Unsupported: ' + msg_type)
raise NotImplementedError('unhandled iopub message: %s' % msg_type)
if _debugging: logging.info('Sending: msg_type: [{}]; HTML: [{}]; TEXT: [{}]'.format(msg_type, out.get('html', ''), out.get('text', '') ))
return out # upstream process will handle it [e.g. send as an oob message]