aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/scripts/py2ipynb.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/scripts/py2ipynb.py b/tools/scripts/py2ipynb.py
new file mode 100755
index 0000000..2496c29
--- /dev/null
+++ b/tools/scripts/py2ipynb.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import argparse
+from IPython.nbformat import v3, v4
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument("input", help="input python file")
+ parser.add_argument("output", help="output notebook file")
+ args = parser.parse_args()
+
+with open(args.input) as fpin:
+ text = fpin.read()
+
+nbook = v3.reads_py(text)
+nbook = v4.upgrade(nbook) # Upgrade v3 to v4
+
+jsonform = v4.writes(nbook) + "\n"
+with open(args.output, "w") as fpout:
+ fpout.write(jsonform)
+
+