Created
August 24, 2017 15:53
-
-
Save cmoscardi/75a4cf2362c49deb36cdd6b991c25786 to your computer and use it in GitHub Desktop.
Jupyter Notebook Output Cleaning Script
This file contains hidden or 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/env ipython | |
import io | |
import sys | |
from nbformat import read, write | |
# Handle either stdin or a filename | |
if __name__ == '__main__': | |
for filename in sys.argv[1:]: | |
ipynb = read(filename, 4) | |
ipynb.metadata.signature = '' | |
for cell in ipynb.cells: | |
if "outputs" in cell: | |
cell["outputs"] = [] | |
if "execution_count" in cell: | |
cell["execution_count"] = None | |
with io.open(filename, mode="w", encoding='utf-8') as fh: | |
write(ipynb, fh) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment