jupyter - how to comment out cells?

后端 未结 4 1208
粉色の甜心
粉色の甜心 2021-02-03 21:17

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

相关标签:
4条回答
  • 2021-02-03 21:53

    You can switch the cell from 'Code to 'Raw NBConvert'

    0 讨论(0)
  • 2021-02-03 21:56

    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.

    0 讨论(0)
  • 2021-02-03 22:04

    If you switch the cell to 'raw NBConvert' the code retains its formatting, while all text remains in a single font (important if you have any commented sections), so it remains readable. 'Markdown' will interpret the commented sections as headers and change the size and colour accordingly, making the cell rather messy.

    On a side note I use this to interrupt the process if I want to stop it - it seems much more effective than 'Kernel --> Interrupt'.

    0 讨论(0)
  • 2021-02-03 22:06

    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.

    0 讨论(0)
提交回复
热议问题