【Python】【VS Code】VS Code中python.json和setting.json文件配置说明

12,490次阅读
没有评论

共计 3210 个字符,预计需要花费 9 分钟才能阅读完成。

目录

1. python.json 配置

2. setting.json 配置

3. 解决中文乱码

4. 实现效果


1. python.json 配置

           python.json 获取步骤:文件 -> 首选项 -> 配置用户代码片段 -> python

           此为 VS Code 的头文件设置,复制以下内容到 python.json

{
    "HEADER":{
    "prefix": "pyheader",
    "body": [   
    "#!/usr/bin/env python3",
    "# _*_ coding : UTF-8 _*_",
    "# 开发团队:ALL",
    "# 开发人员:Admin",
    "# 开发时间:$CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
    "# 文件名称:$TM_FILENAME",
    "# 开发工具:Visual Studio Code",
    "","",
    "","if __name__ == '__main__':","$0"
    ],
    }
}

用法:编辑一个.py 文件, 输入 pyheader,就可以补全以下内容啦

#!/usr/bin/env python3
# _*_ coding : UTF-8 _*_
# 开发团队:ST
# 开发人员:Jly
# 开发时间:2024/02/19 19:30:06
# 文件名称:code_statistics.py
# 开发工具:Visual Studio Code



if __name__ == '__main__':

2. setting.json 配置

        setting.json 获取步骤:文件 -> 首选项 -> 设置

        此为 VS Code 的头文件设置,涉及到环境配置、代码颜色、行间距、字体粗细、中文环境配置等等

{
    "security.workspace.trust.untrustedFiles": "open",
    "workbench.colorTheme": "Oceanic Next (dimmed bg)",
    "workbench.iconTheme": "material-icon-theme",
    "bracket-pair-colorizer-2.depreciation-notice": false,
    "editor.lineHeight": 24,      // 控制行间距
    "editor.fontWeight": "normal",    // 控制字体粗细
    "editor.tokenColorCustomizations": {"comments": "#00ff7f",
    "keywords": "#eb6689",
    "numbers": "#00eeff",
    "functions": "#ea65f9"
    },  // 控制字体颜色
    "python.defaultInterpreterPath": "D:softAnaconda3python.exe",
    //"python.linting.flake8Enabled": true,
    //"python.formatting.provider": "yapf",
    //"python.linting.flake8Args": ["--max-line-length=248"],
    //"python.linting.pylintEnabled": false,
    "python.autoComplete.extraPaths": ["D:/soft/Anaconda3/lib/site-packages",],
    "python.analysis.extraPaths": ["D:/soft/Anaconda3",],
    //"vsicons.dontShowNewVersionMessage": true,
    // 配置 python 语言正常输出中文的环境
    "code-runner.executorMap": {"python":"set PYTHONIOENCODING=utf8 && $pythonPath -u $fullFileName"}, 
    "code-runner.respectShebang": false,
    "editor.unicodeHighlight.includeStrings": false,
    "editor.unicodeHighlight.includeComments": false,
// 终端颜色配置
    "terminal.integrated.inheritEnv": false,
    "workbench.colorCustomizations": {
        "terminal.background": "#200707",
        "terminal.foreground": "#b4d6af",
        "terminalCursor.background": "#D8D8D8",
        "terminalCursor.foreground": "#D8D8D8",
        "terminal.ansiBlack": "#181818",
        "terminal.ansiBlue": "#0b5e7c",
        "terminal.ansiBrightBlack": "#585858",
 
// 终端命令行  lm@os:
        "terminal.ansiBrightBlue": "#39b9e7",
        "terminal.ansiBrightCyan": "#86C1B9",
        "terminal.ansiBrightGreen": "#ca530f",
        "terminal.ansiBrightMagenta": "#BA8BAF",
        "terminal.ansiBrightRed": "#AB4642",
        "terminal.ansiBrightWhite": "#F8F8F8",
        "terminal.ansiBrightYellow": "#f788f7",
        "terminal.ansiCyan": "#86C1B9",
        "terminal.ansiGreen": "#b57b6c",
        "terminal.ansiMagenta": "#BA8BAF",
        "terminal.ansiRed": "#AB4642",
        "terminal.ansiWhite": "#D8D8D8",
        "terminal.ansiYellow": "#F7CA88",
        "terminal.integrated.cursorBlinking": true,
        "terminal.integrated.lineHeight": 1.6,
        "terminal.integrated.letterSpacing": 0.1,
        "terminal.integrated.fontFamily": "Lucida Console", // 字体设置
        "terminal.integrated.shell.linux": "/bin/zsh",
    },
    "[python]": {"editor.formatOnType": true},
    "vsicons.dontShowNewVersionMessage": true,
    "settingsSync.ignoredExtensions": [ ],
    "settingsSync.ignoredSettings": [ ],
    "window.zoomLevel": -1,
    "editor.codeActionsOnSave": {}}

3. 解决中文乱码

        在 setting.json 文件里面增加以下内容即可

// 配置 python 语言正常输出中文的环境
"code-runner.executorMap": {"python":"set PYTHONIOENCODING=utf8 && $pythonPath -u $fullFileName"}, 
"code-runner.respectShebang": false
},

4. 实现效果

原文地址: 【Python】【VS Code】VS Code 中 python.json 和 setting.json 文件配置说明

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-09-30发表,共计3210字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)