在PyCharm中可以先点击Terminal -》输入命令或者在cmd命令行中打开
pip install autopep8
File --》Setting --》Tools --》 External Tools点击左上角的加号
在弹出的界面中输入以下内容后 点击OK --》 Apply
从:后开始复制
Name:autopep8
Program:autopep8
Arguments:--in-place --aggressive --aggressive $FilePath$
Working directory:$ProjectFileDir$
Output filters:$FILE_PATH$:$LINE$:$COLUMN$:.*
复制以下不符合PEP8规范的代码到PyCharm中,代码拷贝自一位博主,链接在这里
import re,os
def demo():
##This is a demo for autopep8
demo_list=['abc',1,'b','2c'];
demo_dict={'1':'Beautiful is better than ugly.','2':'Explicit is better than implicit.',
'3':'Simple is better than complex.','4':'Complex is better than complicated.',
'5':'Flat is better than nested.Sparse is better than dense.'}
if re.search('ab',demo_list[0]):
return demo_list
else:
return demo_dict
print(demo())
右键–》External Tools --》autopep8
执行后代码会自动按照PEP8规范整理