14

Pycharm使用black实现保存即自动格式化代码

 3 years ago
source link: https://www.fdevops.com/2020/04/05/pycharm-black-auto-save
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Pycharm使用black实现保存即自动格式化代码

兰玉磊 • 2020年4月5日 15:46 • Python • 阅读 3930

在平时工作开发中,每个人的代码风格都不一样,后期的维护成本也会比较高,因此我们需要定制代码风格统一标准。

给大家介绍一款可以在代码保存的时候自动格式化的工具black

直接使用pip进行安装

pip install black

获取black的可执行文件

# Linux、mac
$ which black
# windows
$ where black

配置保存即自动格式化代码

打开Preference进行如下配置:

Name: 随便填
File type: Python
Scope: Project Files
Program: 你安装的black的地址
Arguments: $FilePath$ -l 120 # 每行代码长度 120
Output paths to refresh: $FilePath$
Pycharm使用black实现保存即自动格式化代码

本文为原创文章,未经授权禁止转载本站文章。
原文出处:兰玉磊的个人博客
原文链接:https://www.fdevops.com/2020/04/05/pycharm-black-auto-save
版权:本文采用「署名-非商业性使用-相同方式共享 4.0 国际」知识共享许可协议进行许可。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK