Skip to content

Instantly share code, notes, and snippets.

@takluyver
Created July 21, 2016 13:09
Show Gist options
  • Select an option

  • Save takluyver/c7eacd6d52aad4d75cbd48e447f6ad20 to your computer and use it in GitHub Desktop.

Select an option

Save takluyver/c7eacd6d52aad4d75cbd48e447f6ad20 to your computer and use it in GitHub Desktop.

Revisions

  1. takluyver created this gist Jul 21, 2016.
    15 changes: 15 additions & 0 deletions make_nb.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    """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')