我经常需要临时注释一些代码,但在下面这样的情况下,注释一行代码会出现语法错误
if state == False:
print "Here I'm not good do stuff"
else:
# print "I am good here but stuff might be needed to implement"有没有什么东西可以作为NOOP来保持这种语法的正确性?
发布于 2012-09-18 18:24:49
您要查找的操作是pass。因此,在您的示例中,它将如下所示:
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"你可以在这里阅读更多信息:http://docs.python.org/py3k/reference/simple_stmts.html#pass
发布于 2014-09-08 19:23:50
在Python3中,...是一个很好的pass替代品:
class X:
...
def x():
...
if x:
...我把它读成“待完成”,而pass的意思是“此页故意留空”。
它实际上只是一个字面量,就像None,True和False一样,但它们都进行了优化。
发布于 2012-09-18 18:03:48
我发现如果你把代码放在带引号的注释'''comment'''中,它的作用就像一个NOOP,所以你可以放一个三重引号的注释,它将作为一个NOOP,以防代码被删除或用#注释。
对于上述情况:
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" https://stackoverflow.com/questions/12474738
复制相似问题