PyCharm comment print lines

Question:

Is there any shortcut in the IntelliJ IDE such as PyCharm to comment all the lines start with 'print'?

Since during the debug I always write many prints, after the code runs well I want to find a convenient way to comment on all lines starting with 'print'. Now I select each line/block with command + / which is trouble.

Asked By: Michael

||

Answers:

Not sure about pycharm, but I guess you could use find/replace with a regex like '^print' and substitute with '# print'. Maybe you can even make this a macro / Hotkey in pycharm.

Answered By: flurble
Find: (^[ t]*)(print)
Replace: $1## $2
Answered By: Michael

Why not just:

Find: print(
Replace: #print(

And, to get back:

Find: #print(
Replace: print(

This worked pretty well for me. I don’t find the reason for using complex regex for this.

Answered By: Rohit Joshi