Python 如何在 PyCharm 中设置最大行长度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17319422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 07:53:00  来源:igfitidea点击:

How do I set the maximum line length in PyCharm?

pythonpycharmpep8

提问by Ansuman Bebarta

I am using PyCharm on Windows and want to change the settings to limit the maximum line length to 79characters, as opposed to the default limit of 120characters.

我在 Windows 上使用 PyCharm 并希望更改设置以将最大行长度限制为79字符,而不是字符的默认限制120

Where can I change the maximum amount of characters per line in PyCharm?

我在哪里可以更改 PyCharm 中每行的最大字符数?

采纳答案by Alex G.P.

Here is screenshot of my Pycharm. Required settings is in following path: File -> Settings -> Editor -> Code Style -> General: Right margin (columns)

这是我的 Pycharm 的屏幕截图。所需的设置在以下路径中:File -> Settings -> Editor -> Code Style -> General: Right margin (columns)

Pycharm 4 Settings Screenshot

Pycharm 4 设置截图

回答by Marco Sanchez

For PyCharm 4

对于PyCharm 4

File >> Settings >> Editor >> Code Style: Right margin (columns)

文件>>设置>>编辑器>>代码样式:右边距(列)

suggestion:Take a look at other options in that tab, they're very helpful

建议:查看该选项卡中的其他选项,它们非常有用

回答by andy

You can even set a separate right marginfor HTML. Under the specified path:

您甚至可以为 HTML设置单独的右边距。在指定路径下:

File >> Settings >> Editor >> Code Style >> HTML >> Other Tab >> Right margin (columns)

文件>>设置>>编辑器>>代码样式>>HTML>>其他选项卡>>右边距(列)

This is very useful because generally HTML and JS may be usually long in one line than Python. :)

这非常有用,因为通常 HTML 和 JS 通常比 Python 一行长。:)

回答by AB Abhi

For PyCharm 2017

对于 PyCharm 2017

We can follow below: File >> Settings >> Editor >> Code Style.

我们可以按照以下步骤操作:文件>>设置>>编辑器>>代码样式。

Then provide values for Hard Wrap& Visual Guidesfor wrappingwhile typing, tick the checkbox.

然后在键入时为Hard Wrap&提供值Visual Guidesfor wrapping,勾选复选框。

NB: look at other tabs as well, viz. Python, HTML, JSON etc.

注意:也请查看其他选项卡,即。Python、HTML、JSON 等。

回答by lmiguelvargasf

For PyCharm 2018.1 on Mac:

对于 Mac 上的 PyCharm 2018.1:

Preferences (?+,), then Editor -> Code Style:

首选项 ( ?+ ,),然后Editor -> Code Style

enter image description here

在此处输入图片说明

For PyCharm 2018.3 on Windows:

对于 Windows 上的 PyCharm 2018.3:

File -> Settings (Ctrl+Alt+S), then Editor -> Code Style:

文件 -> 设置(Ctrl+ Alt+ S),然后Editor -> Code Style

To follow PEP-8 set Hard wrap atto 80.

遵循 PEP-8 设置Hard wrap at为 80。

回答by Steve Stacha

For anyone, or myself if I reload my machine, who this is not working for when you do a code reformat there is an additional option to check under editor->code style->python : ensure right margin is not exceeded. Once this was selected the reformat would work.

对于任何人,或者我自己,如果我重新加载我的机器,当你进行代码重新格式化时,这对谁不起作用,有一个额外的选项可以在 editor->code style->python 下检查:确保不超过右边距。一旦选择了这个,重新格式化就会起作用。

preference_highlighted

偏好_突出显示