How do I comment out multiple lines in Jupyter Ipy

2019-01-16 02:14发布

I want to comment out a block of multiple lines in Jupyter (Ipython Notebook), but can't find out how to do that in this current version.
It used to be in one of the drop down menus but is no longer there.
How do you comment out multi-line blocks of code at once?

This is not a duplicate because the solution given in the following link doesn't seem to work anymore:
How can I block comment code in the IPython notebook?

Ctrl + / does nothing.

18条回答
相关推荐>>
2楼-- · 2019-01-16 03:10

After searching for a while I have found a solution to comment on an AZERTY mac. The shortcut is Ctrl +/= key

查看更多
【Aperson】
3楼-- · 2019-01-16 03:15

On MacOS 10.11 with Firefox and a German keyboard layout it is Ctrl + ?

查看更多
等我变得足够好
4楼-- · 2019-01-16 03:18

Ctrl + / works for me in Chrome browser in MS Windows

查看更多
小情绪 Triste *
5楼-- · 2019-01-16 03:19

I have not yet managed to find the best way possible. Since I am using a keyboard with Finnish layout, some of the answers do not work for me (e.g. user5036413's answer).

However, in the meantime, I have come up with a solution that at least helps me not to comment each and every line one by one. I am using Chrome browser in MS Windows and I have not checked other possibilities though.

The solution:
It uses the fact that you can have multiple line cursors in an Ipython Notebook.

Press the Alt button and keep holding it. The cursor should change its shape into a big plus sign. The next step is, using your mouse, to point to the beginning of the first line you want to comment and while holding the Alt button pull down your mouse until the last line you want to comment. Finally, you can release the Alt button and then use the # character to comment. Voila! You have now commented multiple lines.

查看更多
聊天终结者
6楼-- · 2019-01-16 03:19

I tried this on Mac OSX with Chrome 42.0.2311.90 (64-bit) and this works by using CMD + /

The version of the notebook server is 3.1.0-cbccb68 and is running on:
Python 2.7.9 |Anaconda 2.1.0 (x86_64)| (default, Dec 15 2014, 10:37:34) 
[GCC 4.2.1 (Apple Inc. build 5577)]

Could it be a browser related problem? Did you try Firefox or IE?

查看更多
甜甜的少女心
7楼-- · 2019-01-16 03:19

If you have a Mac and not a English keyboard: Cmd-/ is still easy to produce.

Follow the below steps:

  1. Just go into the Mac's System Settings, Keyboard, tab "Input Sources" or whatever it might be called in English
  2. Add the one for English (shows up as ABC, strange way to spell English).

Whenever you want a Cmd-/, you have to change to the ABC keyboard (in your menu row at the top of your screen,if you have ticked it to be shown there in the System Settings - Keyboard tab).

Cmd and the key to the left of the right "shift key" gives you Cmd-/.

P.S: Don't forget to switch back to your normal keyboard.

查看更多
登录 后发表回答