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


Python current.reads方法代码示例

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


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

示例1: save_new_notebook

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import reads [as 别名]
def save_new_notebook(self, data, name=None, format=u'json'):
        """Save a new notebook and return its notebook_id.

        If a name is passed in, it overrides any values in the notebook data
        and the value in the data is updated to use that value.
        """
        if format not in self.allowed_formats:
            raise RuntimeError(u'Invalid notebook format: %s' % format)

        try:
            nb = current.reads(data.decode('utf-8'), format)
        except:
            raise RuntimeError(u'Invalid JSON data')

        if name is None:
            try:
                name = nb.metadata.name
            except AttributeError:
                raise RuntimeError(u'Missing notebook name')
        nb.metadata.name = name

        notebook_id = self.write_notebook_object(nb)
        return notebook_id 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:25,代码来源:nbmanager.py

示例2: save_new_notebook

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import reads [as 别名]
def save_new_notebook(self, data, name=None, format=u'json'):
        """Save a new notebook and return its notebook_id.

        If a name is passed in, it overrides any values in the notebook data
        and the value in the data is updated to use that value.
        """
        if format not in self.allowed_formats:
            raise web.HTTPError(415, u'Invalid notebook format: %s' % format)

        try:
            nb = current.reads(data.decode('utf-8'), format)
        except:
            raise web.HTTPError(400, u'Invalid JSON data')

        if name is None:
            try:
                name = nb.metadata.name
            except AttributeError:
                raise web.HTTPError(400, u'Missing notebook name')
        nb.metadata.name = name

        notebook_id = self.write_notebook_object(nb)
        return notebook_id 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:25,代码来源:nbmanager.py

示例3: read_notebook_object

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import reads [as 别名]
def read_notebook_object(self, notebook_id):
        """Get the object representation of a notebook by notebook_id."""
        if not self.notebook_exists(notebook_id):
            raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
        try:
            s = self.blob_service.get_blob(self.container, notebook_id)
        except:
            raise web.HTTPError(500, u'Notebook cannot be read.')
        try:
            # v1 and v2 and json in the .ipynb files.
            nb = current.reads(s, u'json')
        except:
            raise web.HTTPError(500, u'Unreadable JSON notebook.')
        # Todo: The last modified should actually be saved in the notebook document.
        # We are just using the current datetime until that is implemented.
        last_modified = tz.utcnow()
        return last_modified, nb 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:azurenbmanager.py

示例4: collect

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import reads [as 别名]
def collect(self):
        with self.fspath.open() as f:
            payload = f.read()
        self.notebook_folder = self.fspath.dirname
        try:
            # Ipython 3
            self.nb = reads(payload, 3)
        except (TypeError, NBFormatError):
            # Ipython 2
            self.nb = reads(payload, 'json')
        self.runner = NotebookRunner(self.nb)

        cell_num = 1

        for cell in self.runner.iter_code_cells():
            yield IPyNbCell(self.name, self, cell_num, cell)
            cell_num += 1 
开发者ID:zonca,项目名称:pytest-ipynb,代码行数:19,代码来源:plugin.py

示例5: save_notebook

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import reads [as 别名]
def save_notebook(self, notebook_id, data, name=None, format=u'json'):
        """Save an existing notebook by notebook_id."""
        if format not in self.allowed_formats:
            raise RuntimeError(u'Invalid notebook format: %s' % format)

        try:
            nb = current.reads(data.decode('utf-8'), format)
        except:
            raise RuntimeError(u'Invalid JSON data')

        if name is not None:
            nb.metadata.name = name
        self.write_notebook_object(nb, notebook_id) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:nbmanager.py

示例6: read_notebook_object_from_path

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import reads [as 别名]
def read_notebook_object_from_path(self, path):
        """read a notebook object from a path"""
        info = os.stat(path)
        last_modified = tz.utcfromtimestamp(info.st_mtime)
        with open(path,'r') as f:
            s = f.read()
            try:
                # v1 and v2 and json in the .ipynb files.
                nb = current.reads(s, u'json')
            except ValueError as e:
                msg = u"Unreadable Notebook: %s" % e
                raise RuntimeError(msg)
        return last_modified, nb 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:filenbmanager.py

示例7: save_notebook

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import reads [as 别名]
def save_notebook(self, notebook_id, data, name=None, format=u'json'):
        """Save an existing notebook by notebook_id."""
        if format not in self.allowed_formats:
            raise web.HTTPError(415, u'Invalid notebook format: %s' % format)

        try:
            nb = current.reads(data.decode('utf-8'), format)
        except:
            raise web.HTTPError(400, u'Invalid JSON data')

        if name is not None:
            nb.metadata.name = name
        self.write_notebook_object(nb, notebook_id) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:nbmanager.py

示例8: convert_to_ipynb

# 需要导入模块: from IPython.nbformat import current [as 别名]
# 或者: from IPython.nbformat.current import reads [as 别名]
def convert_to_ipynb(py_file, ipynb_file):
    with io.open(py_file, 'r', encoding='utf-8') as f:
        notebook = current.reads(f.read(), format='py')
    with io.open(ipynb_file, 'w', encoding='utf-8') as f:
        current.write(notebook, f, format='ipynb') 
开发者ID:bhmm,项目名称:bhmm,代码行数:7,代码来源:notebookcell_sphinxext.py


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