There's __debug__
, which is a special value that the compiler does preprocess.
if __debug__:
print "If this prints, you're not running python -O."
else:
print "If this prints, you are running python -O!"
__debug__
will be replaced with a constant 0 or 1 by the compiler, and the optimizer will remove any if 0:
lines before your source is interpreted.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…