Created
July 22, 2016 05:00
-
-
Save doowon/a90f1a797ebcdd42a3a1dd77bff71813 to your computer and use it in GitHub Desktop.
nbconvert Python exporter example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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