大家好,又见面了,我是你们的朋友全栈君。
自动的代码格式化工具,兼容 pep8,项目地址为:
官方给出的简介:
Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from
pycodestyle
nagging about formatting. You will save time and mental energy for more important matters.Blackened code looks the same regardless of the project you’re reading. Formatting becomes transparent after a while and you can focus on the content instead.
Black makes code review faster by producing the smallest diffs possible.
pip3 install black
在终端中直接将 black
作为命令来运行,如下截图所示:
运行成功会有输出提示格式化情况。
打开路径:
PyCharm→Preferences→Tools→External tool
点击+
后,输入下面的配置:
# Program
$PyInterpreterDirectory$/python3
# Arguments
-m black $FilePath$
# Working directory
$ProjectFileDir$
然后配置快捷键,打开下面的目录
PyCharm→Preferences→keymap→External Tools→black
右键点击 Add Keyboard Shortcut
,如下图设置快捷键:
成功后,运行快捷方式,会直接格式化你所在窗口的 .py
文件。同样在终端中会显示格式化结果。
可以参考如下博客: PEP8简介
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/172916.html原文链接:https://javaforall.cn