Jupyter - how to comment cells?

Is it possible to comment whole cells in jupyter?

I need this for this case:

I have many cells, and I want to run them all, with the exception of a few of them. I like that my code is organized in different cells, but I do not want to go to each cell and comment on its lines. I prefer to somehow select the cells that I want to comment on and then comment on them at a time (so that I could easily uncomment them later)

thanks

+9
source share
3 answers

I think the easiest way is to change the cell type to โ€œMarkdownโ€ with M when you don't want to run it, and return to โ€œCodeโ€ with Y when you do. In a short test, I did not lose formatting when switching back and forth.

I donโ€™t think you can select multiple cells at the same time.

+9
source

If you switch the cell to "raw NBConvert", the code will retain its formatting, while all the text will remain in one font (it is important if you have any comments), so it remains readable. "Markdown" interprets the commented sections as headers and resizes and colors accordingly, making the cell rather dirty.

On the side of the note, I use this to interrupt the process, if I want to stop it - it seems a lot more efficient than Kernel โ†’ Interrupt.

+9
source

Mark the contents of the cell and press Ctrl + / . It will comment out all the lines in this cell. Repeat the same steps to uncomment the rows of your cell.

+6
source

All Articles