Created
December 25, 2014 17:30
-
-
Save geekman/690f0bb766f9fede911b to your computer and use it in GitHub Desktop.
sequentially re-numbers cells in an IPython Notebook file
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
#!/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