Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython Notebook: Count number of cells in notebook

Answering questions Stack Overflow, I use the same ipython notebook, which makes its easier to search previously given answers.

The notebook is starting to slow down. The question I have is: How do I count the numbers of cells in the notebook?

like image 791
Merlin Avatar asked Dec 14 '22 04:12

Merlin


1 Answers

  1. I recommend you don't use the same ipython notebook for everything. If using multiple notebooks would lead to repeat code, you should be able to factor out common functionality into actual python modules which your notebooks can import.
  2. the notebook is just a json file, if you read the file as a json you can do it easily.

For example:

import json    
document = json.load(open(filepath,'r'))
for worksheet in document['worksheets']:
    print len(worksheet['cells'])    
like image 154
exp1orer Avatar answered Dec 26 '22 19:12

exp1orer