Python 有没有办法防止VSC中的自动格式化程序更改某些行/段代码?
我写了一些python脚本,在大多数情况下,我完全理解autoformatter的工作原理。但有时我希望保持垂直一致性,或者在逻辑上将代码拆分为行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
# 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
全局禁用)