Skip to content

Instantly share code, notes, and snippets.

@hannorein
Created June 21, 2015 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannorein/8423ad75547f37bba228 to your computer and use it in GitHub Desktop.
Save hannorein/8423ad75547f37bba228 to your computer and use it in GitHub Desktop.
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