Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ipynb2py.py
import json
import sys
if len(sys.argv)!=2:
print "Usage: ipynb2py.py FILENAME"
exit(1)
with open(sys.argv[1]) as data_file:
ipynb = json.load(data_file)
code = ""
for c in ipynb["cells"]:
if c["cell_type"] == "code":
source = c["source"]
for s in source:
if s[0] != "%":
code += s.rstrip('\n')+"\n"
exec code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment