當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。