-
-
Save lawlesst/24665cb91ccee29666cfc41a161bbd50 to your computer and use it in GitHub Desktop.
Jupyter Notebook Output Cleaning Script
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 io | |
import sys | |
from nbformat import read, write | |
# Handle either stdin or a filename | |
if __name__ == '__main__': | |
for filename in sys.argv[1:]: | |
print(filename, file=sys.stderr) | |
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 | |
ipynb.metadata.language_info["version"] = 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