Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使某些代码在Python程序中不可执行?_Python 3.x - Fatal编程技术网

Python 3.x 如何使某些代码在Python程序中不可执行?

Python 3.x 如何使某些代码在Python程序中不可执行?,python-3.x,Python 3.x,我想运行代码的某些部分,而不是所有的代码,而我不想执行的代码可以外包出去,但保留在程序中供将来使用 当前代码: for i in v: with open('text.txt'.format(i), 'w') as in_file: in_file.write(xxx) with open('text.txt'.format(i), 'w') as in_file: in_file.write(xxx) 我知道的一种方法是使用“#”作为注释,

我想运行代码的某些部分,而不是所有的代码,而我不想执行的代码可以外包出去,但保留在程序中供将来使用

当前代码:

for i in v:

    with open('text.txt'.format(i), 'w') as in_file:
        in_file.write(xxx)

    with open('text.txt'.format(i), 'w') as in_file:
        in_file.write(xxx)
我知道的一种方法是使用“#”作为注释,但这是非常浪费时间的,因为有时我不想执行100多行代码,我应该全部执行吗?有没有一个很好的方法可以写出100行代码?我甚至尝试了“”<---但它只是将其作为注释,通常在运行程序时,“”中的代码仍然是可执行的

预计来源:

for i in v:

    with open('text.txt'.format(i), 'w') as in_file:
        in_file.write(xxx)

  this>> # with open('text.txt'.format(i), 'w') as in_file:
   this >> #     in_file.write(xxx)

当前没有用于块注释的方法


您的编辑器(如果您使用的是IDE)将具有添加和删除多行注释的选项。

抱歉,由于声誉限制,我无法对此发表评论

如果您使用的是IDE,则可以使用一些快捷键对每一行进行注释。
例如,您可以在Visual Studio代码中使用CTRL+/。它将在所选块的每一行中放置一行注释“#”。谷歌IDE的快捷键。

#注释是最好的答案-通常,您的编辑器会帮助您处理大量代码。您也可以用”环绕或缩进并添加
(如果为False):
,但这些都不太好。谢谢先生的回答。我明白了。好的,非常感谢你的回答。