python VSCode中报错 E501:line too long (81 > 79 characters)

python VSCode中报错 E501:line too long 81 > 79 characters

代码检查报错:E501:line too long 81 > 79 characters)

bash 复制代码
[{
	"resource": "/X:/project/work9/work913/project1/myems/myems-api/reports/equipmentcomparison.py",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "E501",
	"severity": 8,
	"message": "line too long (81 > 79 characters)",
	"source": "Flake8",
	"startLineNumber": 587,
	"startColumn": 80,
	"endLineNumber": 587,
	"endColumn": 80
}]

首先将最大的每行字数的警告限制为120。

问题原因

当前行超出了默认的单行字符配置

解决步骤

  1. 更改Linting选项,

    打开VS Code的设置,搜索Python/Linting,找到Python配置部分,然后选择"Linting: Flake8 Args"设置

  2. 分别添加

    bash 复制代码
    --max-line-length=120
    --ignore=E501
  3. 刷新工作区

    在VS Code中按 Ctrl + Shift + P 或 Cmd + Shift + P 打开命令面板。

    在命令面板中搜索 Developer: Reload Window 并按下回车键。这将重新加载VS Code窗口的所有插件。

代码格式化

上面的22个错误几乎都是代码格式的错误,格式化文档即可

格式化文档之后:

参考文章:
『vscode扩展』代码格式化工具 Black Formatter
python代码格式化工具只懂autopep8?这里有更好的
Visual Studio Code配置自动规范代码格式-超级详细教程!!!

相关推荐
默_笙2 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
小羊没烦恼!2 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
qq_426003962 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技2 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读2 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时2 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
C语言小火车2 天前
C/C++ 为什么需要编译器?
开发语言·c++
奇思妙想聪明勤奋的小羊2 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1232 天前
2026年第38周GitHub趋势周报
python·科技·github