Python NOOP replacement

Often I need to temporarily comment on some code, but there are situations like the following: commenting on one line of code will result in a syntax error

if state == False:
    print "Here I'm not good do stuff"
else:
#    print "I am good here but stuff might be needed to implement"

Is there anything that can act like NOOP so that this syntax is correct?

+5
source share
3 answers

The operation you are looking for is pass. So in your example, it will look like this:

if state == False:
    print "Here I'm not good do stuff"
else:
    pass
#    print "I am good here but stuff might be needed to implement"

You can read more about this here: http://docs.python.org/py3k/reference/simple_stmts.html#pass

+12
source

In Python 3, ...makes a pretty good passsubstitute:

class X:
    ...

def x():
    ...

if x:
    ...

"", pass , " ​​".

, None, True False, .

+6

I found that if you put the code in the tepe specified comment '''comment''', it acts like NOOP, so you can put a triple-quoted comment that will act like NOOP if the code is deleted or commented out with #,

In the above case:

if state == False:
    '''this comment act as NOP'''
    print "Here I'm not good do stuff"
else:
    '''this comment act as NOP and also leaves the 
    else branch visible for future implementation say a report or something'''
#    print "I am good here but stuff might be needed to implement" 
+4
source

All Articles