Python:注释掉一个块标题而不去除里面的所有代码

etu*_*rdu 0 python commenting indentation

有时我需要临时注释掉块标题以进行测试,例如:

i = 2
s = { 'a', 'b', 'c' }

#while i > 0:
  s.pop()
  i -= 1

print(s)
Run Code Online (Sandbox Code Playgroud)

但是,由于缩进是python语法的一部分,如果我运行上面的代码,我得到:

    s.pop()
    ^
IndentationError: unexpected indent
Run Code Online (Sandbox Code Playgroud)

我知道对注释中的代码进行dedenting while会使它工作,但是我想保留代码的可视化结构,而不是每次都进行dedenting和缩进.

有什么技巧可以做到这一点吗?

chm*_*eee 7

什么if True:作为替代?然后只需在while和之间交换'#' if即可获得所需的效果.