Last active
February 22, 2016 00:57
-
-
Save udibr/1d4c71b79dfd360b087d to your computer and use it in GitHub Desktop.
A command line for cleaning ipython notebook from the content of the output cells
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 sys | |
if len(sys.argv) < 2: | |
print "Usage: %s <file-name>"%sys.argv[0] | |
exit(0) | |
fname = sys.argv[1] | |
import json | |
lookup = {'outputs':[], 'execution_count':None} | |
def filter(d): | |
if isinstance(d,dict): | |
d = dict((k,lookup.get(k,filter(v))) for k,v in d.iteritems()) | |
elif isinstance(d,list): | |
d = map(filter,d) | |
return d | |
for fname in sys.argv[1:]: | |
with open(fname,'r') as fp: | |
d = json.load(fp) | |
d = filter(d) | |
with open(fname, 'w') as fp: | |
json.dump(d, fp, sort_keys=True, indent=4, separators=(',', ': ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment