Format on save for a notebook
See original GitHub issueFormatting with ‘Format Cell’ and ‘Format Notebook’ works but saving a notebook does not apply the formatters to each cell like a normal file would.
Example notebook cell that would be formatted if it was python:
\
print("hello, world")
# output
print("hello, world")
Issue Analytics
- State:
- Created 2 years ago
- Reactions:67
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Format a Jupyter notebook on save in VSCode - Stack Overflow
This answer shows how to right click and format a cell or a whole notebook from the right click context menu, or a...
Read more >Save a workbook to text format (.txt or .csv) - Microsoft Support
Save a workbook to text format (.txt or .csv) · Open the workbook you want to save. · Click File > Save As....
Read more >Code formatting in Jupyter cells. TL;DR - Medium
Code formatting in Jupyter cells. TL;DR: I show you how to get simply pretty code in Jupyter notebooks AND Jupyter Lab.
Read more >3.2 Notebook | R Markdown: The Definitive Guide - Bookdown
This preview is generated automatically whenever you save the notebook (whether ... R Notebooks, the notebook file format itself is decoupled from RStudio....
Read more >The Best Format to Save Pandas Data | by Ilia Zaitsev
When working on data analytical projects, I usually use Jupyter notebooks and a great pandas library to process and move my data around....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d also love format on save for notebooks. As mentioned above, I can use
black **/*.ipynb
and it works great (you need to install black with the jupyter extra, eg aspython -m pip install black[jupyter]
), but I’m now just banging my head against the wall trying to get this to run automatically…@NickCrews There is
"editor.codeActionsOnSave"
but it doesn’t allow running arbitrary shell commands (for security reasons?) so you’d need to install an extension like Run On Save and get it call toblack path/to/file.ipynb
on save events.Sadly even that doesn’t work atm since VS Code does not yet expose lifecycle events for notebooks. The issues to upvote for that are
If both get implemented, you should be able to add this to your settings to auto-format Jupyter notebooks: