Skip to content

Instantly share code, notes, and snippets.

@alexeygrigorev
Created May 29, 2021 19:37
Show Gist options
  • Save alexeygrigorev/8ac29445e23ecb754960c5cb971cdd58 to your computer and use it in GitHub Desktop.
Save alexeygrigorev/8ac29445e23ecb754960c5cb971cdd58 to your computer and use it in GitHub Desktop.
import sys
import json
NOTEBOOK_FILE = sys.argv[1]
print(f'messing up with {NOTEBOOK_FILE}')
with open(NOTEBOOK_FILE, 'rt') as f_in:
doc = json.load(f_in)
cnt = 1
for cell in doc['cells']:
if 'execution_count' not in cell:
continue
cell['execution_count'] = cnt
for o in cell.get('outputs', []):
if 'execution_count' in o:
o['execution_count'] = cnt
cnt = cnt + 1
with open(NOTEBOOK_FILE, 'wt') as f_out:
json.dump(doc, f_out, indent=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment