-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
For the python intro course I found a nice preprocessor which can strip notebook cells that contain a certain string (e.g. # solution). This could be used to have notebooks with and without solutions. Might need some changes to the structure of the project.
https://git.iac.ethz.ch/ip_python/ip_python/-/blob/main/intro/strip_solutions
Code under details.
Details
#!/bin/bash
for f in code_with_solutions/*.ipynb; do
[[ -e $f ]] || continue
f=$(basename ${f})
fN_i=code_with_solutions/${f}
# need a relative path
fN_o=code/${f}
if [[ ${fN_i} -nt ${fN_o} ]]; then
# remove all cells that contain "# solution"
jupyter nbconvert \
--to notebook \
--ClearOutputPreprocessor.enabled=True \
--RegexRemovePreprocessor.enabled=True \
--RegexRemovePreprocessor.patterns="['# solution.*']" \
${fN_i} \
--output ../${fN_o}
else
echo "skipping ${fN_i}"
fi
done
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels