Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jupyter - how to comment out cells?

Is it possible to comment out whole cells in jupyter?

I need it for this case:

I have a lot of cells, and I want to run all of them, except for a few of them. I like it that my code is organized in different cells, but I don't want to go to each cell and comment out its lines. I prefer to somehow choose the cells I want to comment out, then comment them out in one go (so I could later easily uncomment them)

Thanks

like image 778
nivniv Avatar asked Sep 07 '15 19:09

nivniv


People also ask

How do you comment out an entire cell in Jupyter?

All you need to do, is select all the lines you want to comment and press Ctrl + / as shown in below video.

What does %% do in Jupyter notebook?

Both ! and % allow you to run shell commands from a Jupyter notebook. % is provided by the IPython kernel and allows you to run "magic commands", many of which include well-known shell commands. ! , provided by Jupyter, allows shell commands to be run within cells.


2 Answers

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

like image 53
sepideh Avatar answered Sep 21 '22 23:09

sepideh


I think the easiest thing will be to change the cell type to 'Markdown' with M when you don't want to run it and change back to 'Code' with Y when you do. In a short test I did, I did not lose my formatting when switching back and forth.

I don't think you can select multiple cells at once.

like image 25
Max Wen Avatar answered Sep 20 '22 23:09

Max Wen