5

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!

1 Answer 1

2

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.