def test_notebook(name): """ Make a test notebook for the given name. """ nb = new_notebook() nb.cells.append(new_code_cell("'code_' + '{}'".format(name))) nb.cells.append(new_raw_cell("raw_{}".format(name))) nb.cells.append(new_markdown_cell('markdown_{}'.format(name))) return nb
def create_code_cell(block): """Create a notebook code cell from a block.""" code_cell = nbbase.new_code_cell(source=block['content']) attr = block['attributes'] if not attr.is_empty: code_cell.metadata \ = nbbase.NotebookNode({'attributes': attr.to_dict()}) code_cell.execution_count = attr.kvs.get('n') return code_cell
def write_to_python_notebook(): cells = [] for index, text in enumerate(data): cells.append(new_code_cell( source=text, execution_count=index, )) nb0 = new_notebook(cells=cells, metadata={ 'language': 'python', }) f = codecs.open(python_notebook_name, encoding='utf-8', mode='w') nbf.write(nb0, f, 4) f.close()
def create_code_cell(block): """Create a notebook code cell from a block.""" code_cell = nbbase.new_code_cell(source=block['content']) attr = block['attributes'] if not attr.is_empty: code_cell.metadata \ = nbbase.NotebookNode({'attributes': attr.to_dict()}) execution_count = attr.kvs.get('n') if not execution_count: code_cell.execution_count = None else: code_cell.execution_count = int(execution_count) return code_cell
new_code_cell, new_markdown_cell, new_notebook, new_output, new_raw_cell ) # some random base64-encoded *text* png = encodestring(os.urandom(5)).decode('ascii') jpeg = encodestring(os.urandom(6)).decode('ascii') cells = [] cells.append(new_markdown_cell( source='Some NumPy Examples', )) cells.append(new_code_cell( source='import numpy', execution_count=1, )) cells.append(new_markdown_cell( source='A random array', )) cells.append(new_raw_cell( source='A random array', )) cells.append(new_markdown_cell( source=u'## My Heading', )) cells.append(new_code_cell(