[Tutor] Comment

David L Neil PyTutor at DancesWithMice.info
Fri Aug 23 19:19:15 EDT 2019


On 24/08/19 10:36 AM, Olsen, Avalow Y wrote:
> Hi,
> 
> Is there a mechanism to comment out large blocks of Python code? So far, the only ways I can see of commenting out code are to either start every line with a #, or to enclose the code in triple quotes.

This question also frustrates me at times!

Your two answers are correct.

- if you use the triple quotes, beware the inclusion of any existing 
multi-line comments!

- some text-editors (I'm currently using SublimeText) offer a command to 
prefix '# plus space' to the current line/highlighted lines, which is 
great for a bulk, temporary removal.


What is required, is to take those lines of code "out of scope". So, 
another technique may be to create a fake class or function - but then 
the code-block still has to be (bulk) indented...


Remember also, that if this code is already a method/function, you could 
do things the other way around, and duplicate the function: such that 
the 'copy' only includes the valid lines of code! (Python will ignore 
the first declaration and only use the second - provided they use the 
same name)

I'll be interested to hear other ideas...
-- 
Regards =dn


More information about the Tutor mailing list