Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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 有没有办法防止VSC中的自动格式化程序更改某些行/段代码?_Python_Visual Studio Code_Autoformatting - Fatal编程技术网

Python 有没有办法防止VSC中的自动格式化程序更改某些行/段代码?

Python 有没有办法防止VSC中的自动格式化程序更改某些行/段代码?,python,visual-studio-code,autoformatting,Python,Visual Studio Code,Autoformatting,我写了一些python脚本,在大多数情况下,我完全理解autoformatter的工作原理。但有时我希望保持垂直一致性,或者在逻辑上将代码拆分为行 # autoformatter removes all leading spaces here array = numpy.array([[ [ 0, 1589, 25825225, 1589, 0], [ 1589, 26265625, 26265625, 262656

我写了一些python脚本,在大多数情况下,我完全理解autoformatter的工作原理。但有时我希望保持垂直一致性,或者在逻辑上将代码拆分为行

# autoformatter removes all leading spaces here
array = numpy.array([[
        [       0,     1589, 25825225,     1589,        0],
        [    1589, 26265625, 26265625, 26265625,     1589],
        [25825225, 26265625, 26265625, 26265625, 25825225],
        [    1589, 26265625, 26265625, 26265625,     1589],
        [       0,     1589, 25825225,     1589,        0],
]])
# autoformatter splits line at '-' sign in the first brackets
links[point.degree - 1].append([
    neighbor.index for neighbor in point.neighbors
])

有没有办法告诉自动格式化程序(我使用VSC的默认Python包)忽略这些行(类似于
#pylint:disable=C0123
magic comment)?

Python扩展支持两个格式化程序:autopep8(默认)和yapf。您可以通过以下配置切换到yapf:

"python.formatting.provider": "yapf"
Yapf支持通过注释将区域排除在格式之外:

# yapf: disable
links[point.degree - 1].append([
   neighbor.index for neighbor in point.neighbors
])
# yapf: enable
我还没有发现autopep8的类似功能(尽管您可以使用
--ignore
全局禁用)