Path: blob/master/pdf/rm_notebook.py
687 views
import os, sys, io12print(sys.argv[1])3infile = open(sys.argv[1], encoding="utf8")4data = infile.read()5infile.close()6outfile = open(sys.argv[1], "w", encoding="utf8")78buf = io.StringIO(data)9first_inline = False10is_code_cell = False11for line in buf:12# can't comment out first inline that is always in the first cell13if '"cell_type":' in line:14is_code_cell = '"code"' in line1516if is_code_cell:17if '%matplotlib inline' in line:18if first_inline:19line = line.replace("%matplotlib inline", "#%matplotlib inline")20first_inline = True2122line = line.replace("%matplotlib notebook", "#%matplotlib notebook")23line = line.replace("time.sleep", "#time.sleep")24line = line.replace("fig.canvas.draw", "#fig.canvas.draw")25line = line.replace("plt.gcf().canvas.draw", "#plt.gcf().canvas.draw")26outfile.write(line)2728outfile.close()293031