Disable python import sorting in VSCode(在 VSCode 中禁用 python 导入排序)
问题描述
我试图在保存文件时禁止 vscode 格式化我的 python 导入.我有一些代码必须在各种导入之间运行,所以顺序很重要,但每次我保存它时都会将导入推到顶部.
I am trying to disable vscode from formatting my python imports when I save my file. I have some code that must run in between various imports so order is important, but every time I save it just shoves the imports to the top.
我试着放了
"editor.codeActionsOnSave": {
"source.organizeImports": false
},
在我的用户设置中,但这并不能解决问题.
in my user settings but that doesn't fix it.
谢谢!
编辑-我想在保存时保持格式化,除了导入
EDIT- I would like to keep formatting on save on except for the imports
推荐答案
检查 vscode 设置中的以下设置,如果是 true 则将其设置为 false 以完全禁用保存时格式化,如下所示:
Check for the below setting in vscode settings, if it's true then set it to false for completely disabling formatting on save, like so :
"editor.formatOnSave": false
为了格式化和忽略不在顶部的导入,首先将上述设置设为 true 并添加到您的用户设置中,然后尝试将此设置添加到您的用户设置中,如果您使用 python 的默认格式化程序,那就是 autopep8 :
for formatting and to ignore imports not being at top itself, first make the above setting true and add to your user settings and try adding this setting to your user settings, if you're using the default formatter for python, that is autopep8 :
"python.formatting.autopep8Args": ["--ignore","E402"]
其中E402表示模块级导入不在文件顶部"
请注意,这仅在您使用默认格式化程序/linter 时才有效.如果您正在使用其他一些 linter,那么我建议您查看他们的文档以了解它是如何完成的.最常见的是可以使用全局配置文件,比如 $HOME/.config/.pycodestyle,并在那里添加必要的设置,例如:
Note that this would only work if you are using the default formatter/linter. If you are using some other linter then i suggest you look up their documentation to see how it's done. Like most commonly one could make use of global config file, say $HOME/.config/.pycodestyle, and add necessary settings there, like :
[pycodestyle]
ignore = E402
格式化程序的参数应作为单独的列表项在引号中传递,例如 ["--ignore","E402"] 而不是 [--ignore=E402]
这篇关于在 VSCode 中禁用 python 导入排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 VSCode 中禁用 python 导入排序


- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01