当前位置: 首页>>代码示例>>Python>>正文


Python NotebookNode.html方法代码示例

本文整理汇总了Python中IPython.nbformat.current.NotebookNode.html方法的典型用法代码示例。如果您正苦于以下问题:Python NotebookNode.html方法的具体用法?Python NotebookNode.html怎么用?Python NotebookNode.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPython.nbformat.current.NotebookNode的用法示例。


在下文中一共展示了NotebookNode.html方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_cell

# 需要导入模块: from IPython.nbformat.current import NotebookNode [as 别名]
# 或者: from IPython.nbformat.current.NotebookNode import html [as 别名]
    def run_cell(self, cell):
        '''
        Run a notebook cell and update the output of that cell in-place.
        '''
        if _debugging: logging.debug('Running cell:\n%s\n', cell.input)
        self.shell.execute(cell.input)
        reply = self.shell.get_msg()
        status = reply['content']['status']
        if status == 'error':
            logging.info('Cell raised uncaught exception: \n%s', '\n'.join(reply['content']['traceback']))
        else:
            if _debugging: logging.debug('Cell returned')

        outs = list()
        while True:
            try:
                msg = self.iopub.get_msg(timeout=1)
                if msg['msg_type'] == 'status':
                    if msg['content']['execution_state'] == 'idle':
                        break
            except Empty:
                # execution state should return to idle before the queue becomes empty,
                # if it doesn't, something bad has happened
                logging.warn('Execution state did not return to idle')
                raise

            content = msg['content']
            msg_type = msg['msg_type']

            out = NotebookNode(output_type=msg_type)

            if 'execution_count' in content:
                cell['prompt_number'] = content['execution_count']
                out.prompt_number = content['execution_count']

            if msg_type in ['status', 'pyin']:
                continue
            elif msg_type == 'stream':
                out.stream = content['name']
                out.html = RClansiconv(content['data'])
            elif msg_type in ('display_data', 'pyout'):
                for mime, data in content['data'].items():
                    try:
                        attr = self.MIME_MAP[mime]
                    except KeyError:
                        logging.warning('unhandled mime type: %s' % mime)
                        raise NotImplementedError('unhandled mime type: %s' % mime)
                    if attr == 'text':
                        if _debugging: logging.info(data)
                        setattr(out, attr, RClansiconv(data))
                    else:
                        setattr(out, attr, data)
            elif msg_type == 'pyerr':
                logging.info('Received an exception: ' + content['ename'])
                out.ename = content['ename']
                out.evalue = content['evalue']
                out.traceback = content['traceback']
                out.html = RClansiconv('\n'.join(out.traceback))
            else:
                raise NotImplementedError('unhandled iopub message: %s' % msg_type)
            outs.append(out)
        cell['outputs'] = outs
开发者ID:nareshbab,项目名称:rcloud,代码行数:64,代码来源:notebook_runner.py


注:本文中的IPython.nbformat.current.NotebookNode.html方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。