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


Python current.read方法代码示例

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


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

示例1: evaluate_notebook

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import read [as 别名]
def evaluate_notebook(nb_path, dest_path=None, skip_exceptions=False):
    # Create evaluated version and save it to the dest path.
    # Always use --pylab so figures appear inline
    # perhaps this is questionable?
    notebook = read(open(nb_path), 'json')
    nb_runner = NotebookRunner(notebook, pylab=True, mpl_inline=True)
    try:
        nb_runner.run_notebook(skip_exceptions=skip_exceptions)
    except NotebookError as e:
        print('\n', '-'*80)
        print(e)
        print('-'*80)
        raise
        # Return the traceback, filtering out ANSI color codes.
        # http://stackoverflow.com/questions/13506033/filtering-out-ansi-escape-sequences
        # return 'Notebook conversion failed with the following traceback: \n%s' % \
        # re.sub(r'\\033[\[\]]([0-9]{1,2}([;@][0-9]{0,2})*)*[mKP]?', '', str(e))
    if dest_path is None:
        dest_path = 'temp_evaluated.ipynb'
    write(nb_runner.nb, open(dest_path, 'w'), 'json')
    ret = nb_to_html(dest_path)
    if dest_path is 'temp_evaluated.ipynb':
        os.remove(dest_path)
    return ret 
开发者ID:choderalab,项目名称:assaytools,代码行数:26,代码来源:notebook_sphinxext.py

示例2: from_notebook_node

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import read [as 别名]
def from_notebook_node(self, nb, resources=None, **kw):
        """
        Convert a notebook from a notebook node instance.
    
        Parameters
        ----------
        nb : Notebook node
        resources : dict (**kw) 
            of additional resources that can be accessed read/write by 
            transformers and filters.
        """
        nb_copy = copy.deepcopy(nb)
        resources = self._init_resources(resources)

        # Preprocess
        nb_copy, resources = self._transform(nb_copy, resources)

        self._load_template()

        if self.template is not None:
            output = self.template.render(nb=nb_copy, resources=resources)
        else:
            raise IOError('template file "%s" could not be found' % self.template_file)
        return output, resources 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:exporter.py

示例3: from_filename

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import read [as 别名]
def from_filename(self, filename, resources=None, **kw):
        """
        Convert a notebook from a notebook file.
    
        Parameters
        ----------
        filename : str
            Full filename of the notebook file to open and convert.
        """

        #Pull the metadata from the filesystem.
        if resources is None:
            resources = ResourcesDict()
        if not 'metadata' in resources or resources['metadata'] == '':
            resources['metadata'] = ResourcesDict()
        basename = os.path.basename(filename)
        notebook_name = basename[:basename.rfind('.')]
        resources['metadata']['name'] = notebook_name

        modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(filename))
        resources['metadata']['modified_date'] = modified_date.strftime(text.date_format)
        
        with io.open(filename) as f:
            return self.from_notebook_node(nbformat.read(f, 'json'), resources=resources,**kw) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:exporter.py

示例4: _transform

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import read [as 别名]
def _transform(self, nb, resources):
        """
        Preprocess the notebook before passing it into the Jinja engine.
        To preprocess the notebook is to apply all of the 
    
        Parameters
        ----------
        nb : notebook node
            notebook that is being exported.
        resources : a dict of additional resources that
            can be accessed read/write by transformers
            and filters.
        """
        
        # Do a copy.deepcopy first, 
        # we are never safe enough with what the transformers could do.
        nbc =  copy.deepcopy(nb)
        resc = copy.deepcopy(resources)

        #Run each transformer on the notebook.  Carry the output along
        #to each transformer
        for transformer in self._transformers:
            nbc, resc = transformer(nbc, resc)
        return nbc, resc 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:exporter.py

示例5: from_file

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import read [as 别名]
def from_file(self, file_stream, resources=None, **kw):
        """
        Convert a notebook from a notebook file.
    
        Parameters
        ----------
        file_stream : file-like object
            Notebook file-like object to convert.
        """
        return self.from_notebook_node(nbformat.read(file_stream, 'json'), resources=resources, **kw) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:exporter.py

示例6: test_export_nbnode

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import read [as 别名]
def test_export_nbnode(self):
        """
        Can a notebook be exported by a notebook node handle?
        """
        with open(self._get_notebook(), 'r') as f:
            notebook = nbformat.read(f, 'json')
            (output, resources) = export_by_name('python', notebook)
        assert len(output) > 0 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_export.py

示例7: get_notebook

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import read [as 别名]
def get_notebook(self, name, path='', content=True):
        self.log.debug('get_notebook: {}'.format(locals()))
        k = self._notebook_s3_key(path, name)
        model = self._s3_key_notebook_to_model(k, timeformat=S3_TIMEFORMAT_GET_KEY)
        if content:
            try:
                with tempfile.NamedTemporaryFile() as f:
                    k.get_file(f)
                    f.seek(0)
                    nb = current.read(f, u'json')
            except Exception as e:
                raise web.HTTPError(400, u"Unreadable Notebook: %s %s" % (os_path, e))
            self.mark_trusted_cells(nb, name, path)
            model['content'] = nb
        return model 
开发者ID:monetate,项目名称:s3nb,代码行数:17,代码来源:ipy2.py

示例8: test_notebook

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import read [as 别名]
def test_notebook(filename):
    nb = read(open(filename), 'json')

    expected = deepcopy(nb['worksheets'][0]['cells'])

    # TODO: figure out how to set the log-level for IPython here
    r = NotebookRunner(nb)
    r.run_notebook()



    actual = r.nb['worksheets'][0]['cells']

    failed = []

    for exp, act in zip(expected, actual):
        if exp['cell_type'] == 'code':
            #print("comparing outputs for ", exp['input'])
            for eo,ao in zip(exp['outputs'], act['outputs']):
                #print("\t", eo['text'], ao['text'], eo['text']==ao['text'])
                eotext = ['\n'.join(l for l in eo['text'].split('\n') if _filter_exceptions(l))]
                aotext = ['\n'.join(l for l in ao['text'].split('\n') if _filter_exceptions(l))]
                if eotext != aotext:
                    #print("\tFAILED")
                    failed.append({'prompt_number': exp['prompt_number'], 'input': exp['input'], 'expected_output': eotext, 'actual_output': aotext})


    return len(failed)==0, failed, r.nb 
开发者ID:phoebe-project,项目名称:phoebe2,代码行数:30,代码来源:ipynbtest.py


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