vscode常用技巧
打开settings.json文件。
·
1、flake8 安装配置
安装
pip install flake8
pip install yapf
pip install black
配置vscode
打开settings.json文件
"python.linting.flake8Enabled": true,
"python.formatting.provider": "yapf",
"python.linting.flake8Args": ["--max-line-length=248"],
"python.linting.pylintEnabled": false
2、常用配置
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{ "python": "/home/jovyan/.conda/envs/torch1.7/bin/python",
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
setting.json
{
"terminal.integrated.fontFamily": "monospace",
"terminal.integrated.fontSize": 16,
"python.envFile": "${workspaceFolder}/.vscode/.env",
"git.ignoreLimitWarning": true,
"flake8.args": [
"--ignore=E501"
],
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
},
}
.env
PYTHONPATH=./:${PYTHONPATH}
3、函数注释插件
Python Docstring Generator
4、vscode中python代码不能跳转
更换Python解释器,选择你安装包的解释器
5、argparse中参数转化字典
为了方便查看argparse 的Namespace 对象中的内容,使用下面方式将其先转成dict,然后print出来。
parser = argparse.ArgumentParser()
parser.add_argument(...)
args = parser.parse_args()
print(json.dumps(vars(args), indent=4))
6、vscode中args异常字符传参
launch.json传参
{
"version": "0.2.0",
"configurations": [
{
"python": "/home/jovyan/.conda/envs/paddle/bin/python",
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": [
"--url",
"https://obs.cn-north-4.myhuaweicloud.com:443/1.4%25%8D%8E%E6%B6%A6%E7%BD%AE%E5%9C%B0%E5%BB%89%E6%B4%81%E4%BB%8E%E4%B8%9A%E5%87%86%E5%88%99.pdf?AccessKeyId=9OGNBX7CRRPA&Expires=1686801&Signature=4Lhj%2BBGDj%2BVyaBYE%3D"
]
}
]
}
以上配置文件传参--url时,由于参数值中存在&字符,会将参数值进行切分,最终输入为https://obs.cn-north-4.myhuaweicloud.com:443/1.4%25%8D%8E%E6%B6%A6%E7%BD%AE%E5%9C%B0%E5%BB%89%E6%B4%81%E4%BB%8E%E4%B8%9A%E5%87%86%E5%88%99.pdf?AccessKeyId=9OGNBX7CRRPA,解决方法将"console": "integratedTerminal"调整为"console": "internalConsole",修改结果如下:
{
"version": "0.2.0",
"configurations": [
{
"python": "/home/jovyan/.conda/envs/paddle/bin/python",
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole",
"args": [
"--url",
"https://obs.cn-north-4.myhuaweicloud.com:443/1.4%25%8D%8E%E6%B6%A6%E7%BD%AE%E5%9C%B0%E5%BB%89%E6%B4%81%E4%BB%8E%E4%B8%9A%E5%87%86%E5%88%99.pdf?AccessKeyId=9OGNBX7CRRPA&Expires=1686801&Signature=4Lhj%2BBGDj%2BVyaBYE%3D"
]
}
]
}
7、Debug源码
添加"justMyCode": false, 形式如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
}
]
}
更多推荐
所有评论(0)