简体   繁体   English

VS Code Python 格式:使用 autopep8 / yapf / black 更改最大行长

[英]VS Code Python Formatting: Change max line-length with autopep8 / yapf / black

I am experimenting with different python formatters and would like to increase the max line length.我正在试验不同的 python 格式化程序,并想增加最大行长度。 Ideally without editing the settings.json file.理想情况下无需编辑settings.json文件。 Is there a way to achieve that?有没有办法做到这一点? 选择格式化程序

For all three formatters, the max line length can be increased with additional arguments passed in from settings, ie:对于所有三个格式化程序,可以通过从设置中传入额外的 arguments 来增加最大行长度,即:

  • autopep8 args: --max-line-length=120 autopep8 参数:--max --max-line-length=120
  • black args: --line-length=120黑色参数: --line-length=120
  • yapf args: --style={based_on_style: google, column_limit: 120, indent_width: 4} yapf args: --style={based_on_style: google, column_limit: 120, indent_width: 4}

Hope that helps someone in the future!希望将来能帮助别人!

在此处输入图像描述

@tkazik answered his own question correctly, however, I thought it would be helpful to include some references: @tkazik 正确回答了他自己的问题,但是,我认为包含一些参考资料会有所帮助:

VSCode documentation on using Python formatters:关于使用 Python 格式化程序的VSCode 文档
https://code.visualstudio.com/docs/python/editing#_formatting https://code.visualstudio.com/docs/python/editing#_formatting

autopep8 command line options: autopep8命令行选项:
https://pypi.org/project/autopep8/#usage https://pypi.org/project/autopep8/#usage

  • Note that there is also an option to point the formatter to a global config file请注意,还有一个选项可以将格式化程序指向全局配置文件
  • Additionally, if you have a local or global config file in the expected location, these preferences will be used automatically by the formatter in VSCode ( https://pypi.org/project/autopep8/#configuration )此外,如果您在预期位置有本地或全局配置文件,VSCode 中的格式化程序将自动使用这些首选项 ( https://pypi.org/project/autopep8/#configuration )

black command line options:黑色命令行选项:
https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#command-line-options https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#command-line-options

yapf command line options: yapf命令行选项:
https://github.com/google/yapf#usage https://github.com/google/yapf#usage

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python AutoPep8 格式不适用于最大行长参数 - Python AutoPep8 formatting not working with max line length parameter VS 代码,Python ext,autopep8 未格式化 - VS Code, Python ext, autopep8 not formatting Python autopep8 和 VS Code 集成 - Python autopep8 and VS Code integration 在 VS 代码 python 笔记本中将 autopep8 和 linting 添加到 jupyter - Add autopep8 and linting to jupyter in VS code python notebook VS Code Python autopep8 不支持 2 个空格悬挂缩进 - VS Code Python autopep8 does not honor 2 spaces hanging indentation 如果我已经安装了 python 扩展,如何将 VS Code 中的路径更改为扩展,以及 autopep8 的正确路径是什么? - How can I change the path in VS Code to the extension and what is the correct path to autopep8 if I already installed the python extension? Autopep8 格式“max-line-length”参数不适用于导入部分 - Autopep8 format "max-line-length" parameter is not working for the imports section 带有 PyLint 和 autoPep8 的 Visual Studio 代码:如何避免 PyLint 抱怨我的行长? - Visual Studio code with PyLint and autoPep8: How can I avoid PyLint to complain about my line length? 如何在 Visual Studio Code 中保存 Python 文件后*自动*运行 *BOTH* black 和 autopep8 *自动*? - How to run *BOTH* black and autopep8 *AUTOMATICALLY* upon saving a Python file in Visual Studio Code? vs-code MS Python扩展程序在Linux上找不到autopep8 - vs-code MS Python extension can't find autopep8 on Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM