nb2py tutorial

All the examples are generated from this notebook and located in the folder tutorial_files.


In [1]:
import nb2py

Exporting marked cells

The dump function automatically exports cells starting with #~, but this behaviour could be changed with the parameter marker.

The markers are removed from the output file.


In [2]:
#~
#This is a cell example with the standard marker
a=2
b=3
print(a+b)


5

In [3]:
nb2py.dump('tutorial.ipynb','tutorial_files/standard.py')

In [4]:
#please export this cell
#This is a cell with a custom comment as marker
x=10
y=11
print(x+y)


21

In [5]:
nb2py.dump('tutorial.ipynb','tutorial_files/custom.py',marker='please export this cell')

Exporting cells by indices

You can also export cells using a list of indices. Consider that the cells will be written regardless of their type.


In [6]:
nb2py.dump_indices('tutorial.ipynb',
                   'tutorial_files/indices.py',
                   indices=[3,5])

In [7]:
nb2py.dump_indices('tutorial.ipynb',
                   'tutorial_files/markdown.md',
                   indices=[0,2,7])