Sometimes I need to temporarily comment out block headings for testing purpose, e.g.:
i = 2
s = { 'a', 'b', 'c' }
#while i > 0:
s.pop()
i -= 1
print(s)
but, since indentation is part of python's syntax, if I run the开发者_如何转开发 code above I got:
s.pop()
^
IndentationError: unexpected indent
I know that dedenting the code inside the commented while
would make it work, but I'd like to preserve a visual structure of my code instead of dedenting and indenting it each time.
Are there any trick to accomplish this?
What about if True:
as the alternate? Then just exchange the '#' between the while
and if
to get your desired effect.
Either use an editor that auto-indent for you or replace the while by something like if True:
temporarily.
精彩评论