你可以如何在PyCharm中自动格式化文档字符串?

huangapple go评论96阅读模式
英文:

How can I auto-format a docstring in PyCharm?

问题

我经常遇到这样的情况:我会在函数的文档字符串中写一段文字,然后过一段时间回来想要在段落中的某一部分添加内容,这会让我不得不重新调整其余的行,使它们的长度合适(既不太长也不太短)。这感觉像是应该有自动化工具可用的事情。

我猜最棘手的部分可能是插件需要理解何时从一行中删除单词并将它们添加到下一行的开头。

是否有一些插件或内置操作可以为我做到这一点?

英文:

I frequently have a situation where I'll write a paragraph in
a docstring for a function, then come back later and want to add to some part of the middle of the paragraph, and that will make me have to re-adjust the rest of the lines to have them be the proper length (not too long, not too short). This feels like something that should have an automation available for it.

I guess the trickiest part would be that the plugin would need to understand when to take words off of one line and add them to the beginning of the next line.

Is there some plugin or built-in action that will do this for me?

答案1

得分: 1

你可以选择文档字符串,然后使用编辑 -> 填充段落进行格式化。

或者,我唯一能想到的自动化工具(在Pycharm中)是选项,在行长度达到一定字符数后自动换行;它在代码风格设置中可用(硬换行于 & 输入时换行)。然而,此设置适用于所有内容(包括代码),而不仅仅是文档字符串。

英文:

You can select the docstring and format it using Edit -> Fill paragraph.

Alternatively the only automated tool I can think of (in Pycharm) is the option which automatically wraps the text after the line length reaches certain number of characters; It is available under Code Style settings (Hard wrap at & Wrap on typing). However, this setting is applied on everything (code included), not just docstring.

huangapple
  • 本文由 发表于 2023年6月5日 00:40:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定