Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93107493
nbstripout
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Nov 26, 06:40
Size
1 KB
Mime Type
text/x-python
Expires
Thu, Nov 28, 06:40 (2 d)
Engine
blob
Format
Raw Data
Handle
22574554
Attached To
rJUPYTERINTRO Jupyter Notebook Introduction
nbstripout
View Options
#!/usr/bin/env python3
"""strip outputs from an IPython Notebook
Opens a notebook, strips its output, and writes the outputless version to the original file.
Useful mainly as a git pre-commit hook for users who don't want to track output in VCS.
This does mostly the same thing as the `Clear All Output` command in the notebook UI.
Adapted from rom https://gist.github.com/minrk/6176788 to work with
git filter driver
# jk: found this here: https://github.com/cfriedline/ipynb_template/blob/master/nbstripout
# jk config:
In .gitattributes add the line:
*.ipynb filter=stripoutput
IN .git/config add the lines (!!adapt path to nbconvert!!):
[filter "stripoutput"]
clean = /home/krausej/bin/nbstripout
smudge = cat
required = true
"""
import
sys
from
nbformat
import
v4
def
strip_output
(
nb
):
"""strip the outputs from a notebook object"""
for
cell
in
nb
.
cells
:
if
'outputs'
in
cell
:
cell
[
'outputs'
]
=
[]
if
'execution_count'
in
cell
:
cell
[
'execution_count'
]
=
0
return
nb
if
__name__
==
'__main__'
:
nb
=
v4
.
reads
(
sys
.
stdin
.
read
())
nb
=
strip_output
(
nb
)
sys
.
stdout
.
write
(
v4
.
writes
(
nb
))
Event Timeline
Log In to Comment