Reputation: 51
I am trying to hide some specific cells when converting an IPython notebook to a notebook. I'd like to use notebooks in class and want to generate 'exercise' notebooks from a master notebook that contains both questions and answers.
This post was very helpful, but for some reason the approach using tags and the preprocessor does not work when converting a notebook to a notebook (it does work when converting to PDF and HTML).
Any thoughts, hints? Thanks in advance!
Upvotes: 5
Views: 540
Reputation: 499
It's pretty simple to do with nbformat (installed with jupyter already):
import nbformat
nb = nbformat.read('Untitled6.ipynb', as_version=4)
for cell in nb.cells.copy():
if 'remove_cell' in cell.metadata.get('tags', []):
nb.cells.remove(cell)
nbformat.write(nb, 'Untitled7.ipynb')
Upvotes: 2