我使用以下命令安装了 yapf:
conda install yapf
并在我的中添加下一行.vscode/settings.json
file:
{
//"python.linting.pylintEnabled": true,
//"python.linting.pycodestyleEnabled": false,
//"python.linting.flake8Enabled": true,
"python.formatting.provider": "yapf",
"python.formatting.yapfArgs": [
" — style",
"{based_on_style: pep8, indent_width: 4}"
],
"python.linting.enabled": true,
}
但我不明白如何使用它 - 它不会在格式错误的脚本中显示任何错误:
import pandas as pd
class MyClass(object):
def __init__(self, some_value: int):
self.value = some_value
def one_more_function(self, another_value):
print(another_value)
myObject = MyClass(45)
myObject.one_more_function(2)
my__object2 = MyClass(324)
print('ok')
def some_foo():
"""
"""
pass
问题出在错误的设置上。
要使用 yapf、black 或 autopep8,您需要:
- 安装 yapf / black / autopep8 (pip install black)
- 配置
.vscode/settings.json
以下一种方式:
文件的一部分:
{
"python.linting.enabled": true,
"python.linting.pylintPath": "pylint",
"editor.formatOnSave": true,
"python.formatting.provider": "yapf", // or "black" here
"python.linting.pylintEnabled": true,
}
关键选项 -"editor.formatOnSave": true,
这个意思yapf
每次保存文档时都会对其进行格式化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)