【问题标题】:How to stop python linter (VSCode) from switching importing order如何阻止python linter(VSCode)切换导入顺序
【发布时间】:2020-06-21 16:13:43
【问题描述】:

我目前在 VSCode 中使用默认的 python linter。然而,linter(Format Document)不断改变模块的导入顺序,如下所示。由于模块(project_settings.py)在当前脚本(preprocess.py)的父目录下,所以我相信我必须在导入之前添加系统路径(在this_01之后)。

我没有遵循正确的PEP8 规则吗? (关注this_02)如何在 linter 不更改导入顺序的情况下将模块导入不同的目录?我需要为 linter 设置某种忽略规则吗?

内部preprocess.py

(在格式化程序之前)

import sys
sys.path.insert(0, './scripts/')
from project_settings import *

(格式化后)

from project_settings import *
import sys
sys.path.insert(0, './scripts/')

项目结构

root
└── scripts
    ├── data-preparation
    │   └── **preprocess.py**
    ├── ...
    ├── main.py
    ├── project_settings.py
    └── utils.py

附言我仍然想使用 Python linter,但想正确使用它,以便 linter 不会改变导入顺序

【问题讨论】:

    标签: visual-studio-code vscode-settings pep8 linter


    【解决方案1】:

    我不确定这是否能回答您的问题,但您可以在 JSON 设置中禁用 Vscode 上的 lint。

    "[python]": {
        "editor.formatOnPaste": false
    }
    
    

    【讨论】:

      猜你喜欢
      • 2023-01-24
      • 1970-01-01
      • 1970-01-01
      • 2016-07-19
      • 2020-01-04
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多