Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sequentially re-numbers cells in an IPython Notebook file
#!/usr/bin/python
#
# sequentially re-numbers cells in an IPython notebook
# 2014.12.26 darell tan
#
import json
import sys
def main():
f1 = open(sys.argv[1], 'rb')
f2 = open(sys.argv[1] + '.new', 'wb')
cell_num = 1
nb = json.load(f1)
for cell in nb['worksheets'][0]['cells']:
if 'prompt_number' in cell:
cell['prompt_number'] = cell_num
cell_num += 1
json.dump(nb, f2, indent=1, separators=(',', ': '), sort_keys=True)
f1.close()
f2.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.