Search code examples
pythonjupyter-notebookjupyterjupyterhubnbconvert

How to skip specific cells while converting a notebook to python script?


I am trying to convert a Jupyter notebook to a python file using nbconvert command. There is a cell having Python code which I want it to skip while converting. I tried few solutions including adding remove_cell tag to the one that has to be skipped:

"jupyter nbconvert <notebook_path> --TagRemovePreprocessor.enabled=True --TagRemovePreprocessor.remove_cell_tags=\"['remove_cell']\" --to script

But it did not work. Please let me know if this can be done through nbconvert.


Solution

  • The question needs a somewhat better specification (what is the output you get, in the script and on screen; code fragments; etc).

    Even so, a few things you may try:

    1. Using --to python instead of --to script (see this, although it may be old for your version).

    2. Change delimiters for the tag. In an example in the link above: --TagRemovePreprocessor.remove_cell_tags='{"note"}'. In this other example: --TagRemovePreprocessor.remove_cell_tags={\"Hide\"} And some more.