Python Forum
disable a block of code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: disable a block of code (/thread-12292.html)



disable a block of code - Skaperen - Aug-18-2018

while doing some initial testing, i want to disable a block of code. many other languages have a specific comment start and end symbol. but Python doesn't.

can i achieve this by adding a line with ''' before and after the code to be disabled as long as the indentation resumes at the same depth? i tried and it works. but i don't what pitfalls there are, besides some other existing use of '''.


RE: disable a block of code - micseydel - Aug-18-2018

Yes, Python uses tripe-quotes for block comments as well as strings.


RE: disable a block of code - Gribouillis - Aug-18-2018

(Aug-18-2018, 04:10 AM)Skaperen Wrote: while doing some initial testing, i want to disable a block of code.
In a good editor, such as Kate, you can select a block of code and comment it out with a keyboard shortcut.


RE: disable a block of code - Skaperen - Aug-19-2018

i see """ used in lots of places but i never see ''' used. early on i even thought """ was the only allowed way to do triple quoting until i was curious enough to actually try it. so my thought is that i will use ''' since it is less likely to run into a legit string literal using ''' than the others. even so, it would have been nice to have something for block comments like /* in a few other languages. and, IMHO, making it nestable would be a plus (though arguments against that can be easily made).


RE: disable a block of code - metulburr - Aug-20-2018

When do you actually put that many comments into code?

the triple quotes of docstrings handle descriptions for every piece of code. If you wanted to use it for block comments, you could do that also.

and i always use single quotes for everything in python, unless im trying to avoid escaping one by using double quotes.

Quote:i want to disable a block of code.
besides triple quotes, depending on what i want to switch off and on, I will put my code into a class and just comment out the creation of the instance (assuming that is not referred to again). However thats if it called for being in a class in the first place.



RE: disable a block of code - Skaperen - Aug-20-2018

i comment my code as i write it and/or as i rewrite it. but less then 5% is commented. i am trying to increase that percentage, particularly for what i (intend to) release to the public.