Skip to content

Instantly share code, notes, and snippets.

@AngelBerihuete
Forked from takluyver/make_nb.py
Created October 19, 2017 06:29
Show Gist options
  • Save AngelBerihuete/48dfbeb497fcab8a1651d672091af790 to your computer and use it in GitHub Desktop.
Save AngelBerihuete/48dfbeb497fcab8a1651d672091af790 to your computer and use it in GitHub Desktop.
Make a notebook from a script
"""Create a notebook containing code from a script.
Run as: python make_nb.py my_script.py
"""
import sys
import nbformat
from nbformat.v4 import new_notebook, new_code_cell
nb = new_notebook()
with open(sys.argv[1]) as f:
code = f.read()
nb.cells.append(new_code_cell(code))
nbformat.write(nb, sys.argv[1]+'.ipynb')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment