开发者

Python: Comment out a block heading without dedenting all the code inside

开发者 https://www.devze.com 2023-04-01 21:29 出处:网络
Sometimes I need to temporarily comment out block headings for testing purpose, e.g.: i = 2 s = { \'a\', \'b\', \'c\' }

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消