学无先后,达者为师

网站首页 编程语言 正文

Pycharm使用技巧_Pycharm配置autopep8

作者:卢同学HLLY 更新时间: 2022-07-13 编程语言

1、关于PEP8
官网地址:https://www.python.org/dev/peps/pep-0008/

PEP 8,Style Guide for Python Code,是Python官方推出编码约定,主要是为了保证Python编码的风格一致,提高代码的可读性。

2、关于Autopep8
github地址:https://github.com/hhatto/autopep8

Autopep8是自动将Python代码格式化为符合PEP 8风格的工具。
它使用pycodestyle工具来确定代码的哪些部分需要被格式化。
Autopep8能够修复大部分pycodestyle检测的格式问题。

3、下载安装Autopep8

 pip install autopep8

4、Pycharm配置Autopep8方法

1、选择菜单「File」–>「Settings」–>「Tools」–>「External Tools」–>点击加号添加工具

在这里插入图片描述

2、填写如下配置项,点击「OK」保存
Name:autoPEP8 (可随意填写) 
Programs:autopep8 
Parameters:--in-place --aggressive $FilePath$
Working directory:$ProjectFileDir$

在这里插入图片描述

3、编写完代码后,右键选择「Extern Tools」–>「autopep8」

在这里插入图片描述5、使用autopep8前后代码对比

使用前

在这里插入图片描述

使用后

在这里插入图片描述

原文链接:https://blog.csdn.net/weixin_44801980/article/details/125645932

栏目分类
最近更新