Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rlabbe
GitHub Repository: rlabbe/Kalman-and-Bayesian-Filters-in-Python
Path: blob/master/pdf/rm_notebook.py
687 views
1
import os, sys, io
2
3
print(sys.argv[1])
4
infile = open(sys.argv[1], encoding="utf8")
5
data = infile.read()
6
infile.close()
7
outfile = open(sys.argv[1], "w", encoding="utf8")
8
9
buf = io.StringIO(data)
10
first_inline = False
11
is_code_cell = False
12
for line in buf:
13
# can't comment out first inline that is always in the first cell
14
if '"cell_type":' in line:
15
is_code_cell = '"code"' in line
16
17
if is_code_cell:
18
if '%matplotlib inline' in line:
19
if first_inline:
20
line = line.replace("%matplotlib inline", "#%matplotlib inline")
21
first_inline = True
22
23
line = line.replace("%matplotlib notebook", "#%matplotlib notebook")
24
line = line.replace("time.sleep", "#time.sleep")
25
line = line.replace("fig.canvas.draw", "#fig.canvas.draw")
26
line = line.replace("plt.gcf().canvas.draw", "#plt.gcf().canvas.draw")
27
outfile.write(line)
28
29
outfile.close()
30
31