Search code examples
jupyter-notebooknbconvert

how to access jupyter tag with nbconvert


I added a tag "hide input" to a code cell in Jupyter. This nicely shows up in the meta data:

"cell_type": "code",
"execution_count": 126,
"metadata": {
  "tags": [
  "hide_input"
 ]

When doing nbconvert, I use a template where I check if this tag is present. This doesn't find it:

if cell.metadata.hide_input

And this throws an error

if cell.metadata.tags.hide_input

The error is

'nbformat.notebooknode.NotebookNode object' has no attribute 'tags'

Any thought on what the syntax is to check if the tag is applied? (Or a reference to the docs - I haven't been able to find it, sorry).


Solution

  • Found it in the nbconvert docs (was looking in the Jupyter docs):

    if 'hide_input' in cell['metadata'].get('tags', []):