有没有快速缩进大量代码的方法?

Is there a quick way to indent large amounts of code?

我正在通过功能化来简化我的代码(是的,我知道这是错误的,但我称之为..),我意识到我有大约 100 行代码需要缩进。我的问题是,有没有一种快速的方法可以在 python 中缩进大块代码。(IDLE 编辑器,如果可能的话使用键盘快捷键。)

感谢您的帮助,提问完毕!

如果您想缩进 python 文件,autopep8 会为您完成。

pip install --upgrade autopep8

然后

autopep8 --in-place path/to/file

如果您使用的是 Sublime Text,您可以 ctrl + ] 缩进突出显示的文本块,同样 ctrl + [ 取消缩进。 cmd OSX 用户。

你也可以重新缩进,让整个代码看起来更漂亮。 Edit → Line → Reindent

很多编辑器都有这方面的功能。 idle中集成的编辑器有:Format / Indent region和Format / Dedent region

你可以试试PyCharm, which can help you to indent your code. Detailed features about PyCharm can be found here