Commenting out a block of code

Is there a way to comment out a block of code in the script editor rather than using the # character for each line?

Thanks,
Nate

You can highlight the block of code and then do a Ctrl+/ to comment the entire block quickly, then to un-comment, highlight the entire block and press Ctrl+Shift+/ . Still uses # characters but it’s quick. Hope this helps.

I know it is old but maybe someone can help, I tried to do as suggested above but nothing happened…any suggestion? By the way, my keyboard is in AZERTY mode

2 Likes

Another way to comment out the block of code, which might work better for you, is by turning it into a string with triple quotes.
If you go to the very beginning of the block of code you want to comment out and type “”" that turns everything from that point onward in your code into a string. Then, you can go to the end of the block you want commented out and put another “”" to signify the end of the string. Since that whole block is now turned into a string, it is effectively commented out of your code. It’s a nice Python trick to know :slight_smile:

This works fine, thanks !

I do it this way,
I select the portion of the code i need to comment, starting from the bottom ( don’t ask me why, just trust me ), then i press ctrl + \ and then type # on multiple lines.

1 Like

It worked this way ,thanks luca :grinning:

it doesn't work for me, how did you do that?

If you do this in the script console, the whole block will be printed as a string.
To avoid this, assign the whole thing to a variable:

_ = """
...
whole block of code
...
"""

just as luca said , select the portion of the code i need to comment, starting from the bottom , then press ctrl + \

check the video

It's possible if you have a different Keyboard layout that you need a different key combination, in order to do this.

Does this work for you on your keyboard?

I never had an issue with ctrl + / to comment things, but I'm on a qwerty.
I know my fellow Frenchies can't do it with the regular azerty layouts we have in France.

EDIT: These don't seem to actually work, unfortunately, thanks @pascal.fragnoud. Leaving in for future reference

@Transistor suggested a couple possibilities awhile back but not sure if they have been confirmed to work or not.

This threw me off. It's ctrl + /. It works for me this way.

4 Likes

sorry, it is ctrl + / , you are right , I did not notice this mistake

I just switched to azerty (which I need to keep for accents éùöî, you should see me switch between layouts every 1.2 seconds when I need to type something in French. It's not pretty. On Linux I switch to an international layout that allows me to type accents, but I couldn't find something that works well on Windows) to try and none of the combinations worked.

1 Like

I use a standard qwerty setup and ctrl+/ works as expected for me, but I know that different layouts, such as apparently French AZERTY will send a different character code for the same key combination and that can sometimes result in shortcuts not working as expected.

1 Like

I type accents with a compose key on Linux. (I use the windows key as compose, since it's just sitting there.)

áèïöçñ

2 Likes

Don't make me learn yet another layout/method, I'm full :grimacing: