autopep8怎么利用Pycharm进行配置?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
关于PEP 8
PEP 8,风格指南forPythonCode,是Python官方推出编码约定,主要是为了保证Python编码的风格一致,提高代码的可读性。
官网地址:https://www.python.org/dev/peps/pep-0008/
关于autopep8
autopep8是自动将Python代码格式化为符合PEP 8风格的工具。它使用pycodestyle工具来确定代码的哪些部分需要被格式化.Autopep8能够修复大部分pycodestyle检测的格式问题。
github地址:https://github.com/hhatto/autopep8
下载安装autopep8
pip安装autopep8
使用autopep8
命令行使用方式如下
autopep8美元——就地激进——积极& lt; filename>
autopep8美元——就地——激进——积极Student.py
Pycharm配置autopep8方法
1)具体流程:选择菜单“文件”→“设置”→“工具”→“外部工具”→设置相关配置→点击加号添加工具
填写如下配置项,点击“OK”保存
设置→工具→外部工具点击添加按钮名称:autopep8(可以自定义)
工具设置:
程序:autopep8(不能修改)
引用>
参数:——就地——激进——积极FilePath
美元工作目录:$ ProjectFileDir $
高级选项:在输出过滤器添加:FILE_PATH \美元:线\:美元列\:美元。*
3)使用autopep8自动格式化你的python代码
import 数学 def 例二(): some_tuple 才能=,(1,,2,,3,,& # 39;一个# 39;) some_variable 才能=,{ ,,,& # 39;长# 39;:,& # 39;Long code lines should be wrapped within 79年,字符强生# 39; ,,,& # 39;其他# 39;:,(math.pi,, 100,, 200,, 300,, 9876543210, & # 39;却;能够is a long string that goes 在# 39;], ,,,& # 39;更多# 39;:,{,& # 39;内部# 39;:,& # 39;却;能够whole logical line should be 包裹# 39;公司,some_tuple:, (1, 20, 300, 40000, 500000000, 60000000000000000]}} return 才能;(some_tuple, some_variable) , def example2 ():, return (& # 39; & # 39;,拷贝{& # 39;f # 39;:, 2}),拷贝{& # 39;has_key (), is 弃用# 39;:,真正的}; , class 青年们(对象): def 才能__init__(自我,,酒吧): ,,,#,Comments should have a space after 从而散列。 ,,,if 酒吧: ,,,,,bar +=1 ,,,,,bar =, bar *,酒吧 ,,,: ,,,,,some_string =,“““ ,,,,,,,,,,,Indentation 拷贝multiline strings should not be touched.Only actual code should be reindented。 “““第一种方式:
编写完代码后,右键选择“走读生工具”→“autopep8”
![]()
第二种方式:
选择菜单“工具”→“走读生工具”→“autopep8”即可
![]()
看完上述内容,你们掌握autopep8怎么利用Pycharm进行配置的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
autopep8怎么利用Pycharm进行配置