Nbconvert: Error when running nbconvert from a notebook cell with `--TagRemovePreprocessor.remove_cell_tags`

Created on 3 Apr 2020  路  3Comments  路  Source: jupyter/nbconvert

Running the following from command line works fine

jupyter nbconvert test.ipynb --TagRemovePreprocessor.remove_cell_tags='{"to_remove"}'

However, when I try to run it from a notebook code cell (with a prepended !) I get the following error message:

traitlets.traitlets.TraitError: The 'remove_cell_tags' trait of a TagRemovePreprocessor instance must be a set, but a value of class 'str' (i.e. 'to_remove') was specified.

I have tried enabling the TagRemovePreprocessor and change the quoting/escaping as suggested on SO, but the error remains.

I can't figure out how to pass a set since it is always converted to a string. Is this a bug, or is there anything I can do to fix it on my end?

Package versions:

nbconvert           5.6.1
notebook            6.0.3
IPython             7.12.0
jupyter_client      5.3.4
jupyter_core        4.6.3
jupyterlab          1.2.6
-----
Python 3.8.1 | packaged by conda-forge | (default, Jan 29 2020, 14:55:04) [GCC 7.3.0]
Linux-5.5.13-arch1-1-x86_64-with-glibc2.10

Most helpful comment

I just tried this with nbconvert 6.0.2 and it seems like single { and } works from inside the notebook now, so just an update in case anyone else comes across this.

All 3 comments

It's the { and } characters causing problems. Try replacing your { with {{ and } with }}

See these examples:

foo = 'bar'
!echo {foo} # Prints bar
foo = 'bar'
!echo {{foo}} # Prints {foo}

Work like a charm, thank you!

I tried backslashes and nested quotation marks, but didn't think of doubling the curly braces. I guess the syntax is not fully portable between shell commands in the notebook and in terminal since the double braces didn't work there. But that inconvenience is minuscule.

I just tried this with nbconvert 6.0.2 and it seems like single { and } works from inside the notebook now, so just an update in case anyone else comes across this.

Was this page helpful?
0 / 5 - 0 ratings