Skip to content

Instantly share code, notes, and snippets.

@akarve
Created January 30, 2019 23:20
Show Gist options
  • Save akarve/4d15c819973e495e9ce44275b0079022 to your computer and use it in GitHub Desktop.
Save akarve/4d15c819973e495e9ce44275b0079022 to your computer and use it in GitHub Desktop.
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