Created
November 28, 2020 03:11
-
-
Save keineahnung2345/38dda2c61c49169e775c9d80648e0d44 to your computer and use it in GitHub Desktop.
A python script to parse commands and outputs from jupyter notebook
This file contains 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 json | |
nb_fname = "xxx.ipynb" | |
with open(nb_fname, "r", encoding="utf-8") as f: | |
nb = json.load(f) | |
cells = nb['cells'] | |
print("There are", len(cells), "cells") | |
for cell in cells: | |
source = ''.join(cell['source']) | |
print(source) | |
outputs = cell['outputs'] | |
if len(outputs) == 0: | |
continue | |
try: | |
text = ''.join(outputs[0]['data']['text/plain']) | |
except: | |
text = ''.join(outputs[0]['text']) | |
print(text) | |
print("===========================") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment