Created
January 30, 2019 23:20
-
-
Save akarve/4d15c819973e495e9ce44275b0079022 to your computer and use it in GitHub Desktop.
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
NB_VERSION = 4 | |
def extract_text(notebook_str): | |
formatted = nbformat.reads(notebook_str, as_version=NB_VERSION) | |
text = [] | |
for cell in formatted.get('cells', []): | |
if 'source' in cell and 'cell_type' in cell: | |
if cell['cell_type'] == 'code' or cell['cell_type'] == 'markdown': | |
text.append(cell['source']) | |
return '\n'.join(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment