When you use ipynb notebooks for lectures and exercises, you might want to have a single notebook file from which you can easily compile both the training notebook, as well as the solution.
This script presents a way to create these:
./make_notebook.py -f example/example.ipynb
This will create example_exercise.ipynb
as well as example_solution.ipynb
.
You can mark a cell (either markdown or code) to be included either in the exercise, solution, or both.
To be included only in the exercise, start the cell with #!!exercise
, and solution cells with #!!solution
.
Cells without such markers will be included in both output files.
See the folder example
for a working example.
usage: make_notebook.py [-h] -f FILENAME [-e OUT_EXERCISE] [-s OUT_SOLUTION] [--token_exercise TOKEN_EXERCISE] [--token_solution TOKEN_SOLUTION]
optional arguments:
-h, --help show this help message and exit
-f FILENAME, --filename FILENAME
The input .ipynb file.
-e OUT_EXERCISE, --out_exercise OUT_EXERCISE
Optional, where to write output exercise to.
-s OUT_SOLUTION, --out_solution OUT_SOLUTION
Optional, where to write output solution to.
--token_exercise TOKEN_EXERCISE
Optional, use another token to mark exercise cells in the ipynb file.
--token_solution TOKEN_SOLUTION
Optional, use another token to mark solution cells in the ipynb file.