0

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.

Arjun A J
  • 396
  • 1
  • 9
  • 34
  • Sounds like it would just be easier to open the .py file after and remove manually – Kurtis Streutker Sep 26 '19 at 14:45
  • Note that the TagRemovePreprocessor is only available in nbconvert 5.3 and above: `https://nbconvert.readthedocs.io/en/latest/changelog.html?highlight=TagRemovePreprocessor` – Sreeram Nair Sep 26 '19 at 15:01
  • @KurtisStreutker The requirement is to get rid of manual editing of python file. Please suggest a way if you know about it. Thank you in advance – Arjun A J Sep 26 '19 at 17:21
  • @SreeramNair I'm on version 5.4.0 but I believe TagRemovePreprocessor converts a notebook from one form to another, but not to python script or .py format. Please correct me if I'm wrong, with a working example if possible. Thank you – Arjun A J Sep 26 '19 at 17:25

1 Answers1

0

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.