Byte_Monster
Byte_Monster

Reputation: 313

python script ambiguous error message

I am using jupiter notebooks and root with C++ kernel in order to create some interactive documentation. The documentation includes some histograms and other graphs, so I am using the magic %%jsroot in order to make the graphs interactive. The magic is produsing javascript instead of just images so they can be interactive.

Everything works until I try to use nbconvert to turn the notebooks into a pdf file. Since the javascript can not be transfered to pdf I am using a script to remove the cell where I call the %%jsroot and re-run the notebook in order to create the images. The %%jsroot comand is called in a separate cell. This is my script:

import string import sys infilename = sys.argv[1] outfilename = sys.argv[2]

f = open(infilename)
lines = f.readlines()
f.close()
text = "".join(lines)

true=True
false=False

nbj = eval(text)

cells = nbj["cells"]

newcells=[]
jscount = 0
mustdecrement = False
for cell in cells:
   if cell["source"][0] == "%%jsroot on":
     mustdecrement = True
     jscount = 1
     continue
   else:
     if mustdecrement:
       cell["execution_count"] -= 1
     newcells.append(cell)
nbj["cells"] = newcells

if jscount == 1:
   newnb = open(outfilename,"w")
   newnb.write(str(nbj))
   newnb.close()

It gives me the error:

Traceback (most recent call last): File "removeJS.py", line 28, in cell["execution_count"] -= 1 KeyError: 'execution_count'

Any ideas what this could be?

Upvotes: 0

Views: 190

Answers (1)

Byte_Monster
Byte_Monster

Reputation: 313

I found this one (simple logic error). The execution_count property did not exist on the markdown cells so it was not found.

Upvotes: 1

Related Questions