Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nbconvert Python exporter example
import nbformat
from nbconvert import PythonExporter
exporter = PythonExporter()
(source, meta) = exporter.from_filename('something.ipynb')
# When NB object is used.
#with open('something.ipynb', 'r') as infile:
#nb = nbformat.reads(infile.read(), nbformat.NO_CONVERT)
#(source, meta) = exporter.from_notebook_node(nb)
with open('something_out.py','w') as outfile:
outfile.writelines(source.encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment