vscode常用技巧

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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于在VSCode中编写代码时的一些技巧,我可以给你提供几个建议。首先,快捷键是提高效率的关键。你可以在VSCode中掌握一些常用的快捷键,例如使用Ctrl+S保存文件,Ctrl+X剪切行,Ctrl+C复制行,Ctrl+V粘贴行等。此外,你还可以使用Ctrl+Shift+L选中所有匹配项,Ctrl+D多重选择相同的词,Ctrl+Shift+[折叠代码区块,Ctrl+Shift+]展开代码区块等。 其次,你可以安装一些适用于特定编程语言的插件,这样可以提供更好的开发体验。VSCode的插件市场中有大量的插件可供选择。你可以根据自己的需要,安装一些提供代码补全、语法高亮、调试支持等功能的插件。 另外,你还可以利用VSCode的内置终端进行代码运行和调试。VSCode提供了集成的终端,可以在编辑器中直接执行命令并查看输出结果。你可以使用Ctrl+`打开终端,然后在终端中运行你的代码。 最后,你还可以自定义VSCode的设置,以适应个人的偏好和习惯。你可以调整字体大小、主题颜色、缩进设置等,以使得代码在编辑器中更易读。 综上所述,通过掌握快捷键、安装适用的插件、使用内置终端和自定义设置,你可以更高效地在VSCode中编写代码。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [开发工具-vscode 使用技巧](https://blog.csdn.net/xiaoliizi/article/details/125089572)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值