Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python NOOP replacement [duplicate]

Often I need to temporary comment some code, but there are situations like the following where commenting a single line of code will get 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 something that might act as an NOOP to keep this syntax correct?

like image 612
Eduard Florinescu Avatar asked Sep 18 '12 10:09

Eduard Florinescu


2 Answers

The operation you're looking for is pass. So in your example it would 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 it here: http://docs.python.org/py3k/reference/simple_stmts.html#pass

like image 57
while Avatar answered Oct 04 '22 22:10

while


In Python 3, ... makes a pretty good pass substitute:

class X:
    ...

def x():
    ...

if x:
    ...

I read it as "to be done", whereas pass means "this page intentionally left blank".

It's actually just a literal, much like None, True and False, but they optimize out all the same.

like image 45
Veedrac Avatar answered Oct 04 '22 22:10

Veedrac