(Go: >> BACK << -|- >> HOME <<)

Skip to content

Python script to clear output cells from Jupyter notebook. See README for git commit hook implementation.

License

Notifications You must be signed in to change notification settings

caallinson/jupyter-clear-output

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jupyter-clear-output

Python script to clear output cells from Jupyter notebook (Note: notebook must be saved in JSON format with .ipynb extension)

Use: jupyter-clear-output.py <notebook file>

Optional flag: -f to force run on files without .ipynb extension

Use this to clear outputs from Jupyter notebooks before commiting to Git.

Add jupyter-clear-output.py to .git\hooks\ and the below to .git\hooks\pre-commit:

## Change Path to Python Here: ##

python_path=python

#python_path=~/Anaconda3/python

##

shopt -s nullglob

for i in **/*.ipynb; do

$python_path ./.git/hooks/jupyter-clear-output.py $i

done

for i in *.ipynb; do

$python_path ./.git/hooks/jupyter-clear-output.py $i

done

git add .

Alternatively, use pre-commit.sample file provided (remove .sample extension for use)

Note: Path to python must either be in the environment or replace python with path to your interpreter (ex: ~/Anaconda3/python) in python_path variable