使用sublime方便python编程,但有时代码写得比较紧凑,不符合规范,怎么能更规范呢,
就是使用
AutoPep8插件来调整Python代码,使其符合PEP8的要求
快捷键为:
(ctrl+shift+8)。
安装:ctrl+shift+P
选中:Package Control :Install Package
寻找:AutoPep8 插件安装就可以了
出现此信息,安装成功
Package Control Messages
AutoPEP8
Sublime Auto PEP8 Formatting
(https://github.com/wistful/SublimeAutoPEP8)
Automatically formats Python code to conform to the PEP 8 style guide using autopep8 module
Supports ST3 only.
Features:
format / preview code according PEP8
format / preview selected text
format / preview all python modules in folder
side bar menu
formated code while saving
Using:
SideBar - right click on the file(s) or folder(s)
Active view - right click on the view
Selected text - right click on the selected text
On Save - provide by settings: option format_on_save
Command Palette - bring up the Command Palette and select PEP8: Format Code
or PEP8: Preview Changes
Hotkeys - Command/Control + Shift + 8
to format code, Command/Control + 8
to preview changes
如果已经安装了某些插件不喜欢,还可以删除
进入package control,搜索remove package,进入后选择要删除的插件即可!
整理前程序:
num=int(input("输入评委人数 "))
chengji=[]
for i in range(1,int(num)+1):
fen=111
while fen>100 or fen<0:
fen=int(input('第%d个评委分数'%i))
if fen>100 or fen<0:
print('必须是0-100的实数')
chengji.append(fen)
print('去掉一个最高分%d'%max(chengji))
chengji.remove(max(chengji))
print('去掉一个最低分%d'%min(chengji))
chengji.remove(min(chengji))
print('最后得分%.2f'%(sum(chengji)/len(chengji)))
整理后程序,发现=两边,> < 两边都已经有了空格,分隔更明晰了,
num = int(input("输入评委人数 "))
chengji = []
for i in range(1, int(num)+1):
fen = 111
while fen > 100 or fen < 0:
fen = int(input('第%d个评委分数' % i))
if fen > 100 or fen < 0:
print('必须是0-100的实数')
chengji.append(fen)
print('去掉一个最高分%d' % max(chengji))
chengji.remove(max(chengji))
print('去掉一个最低分%d' % min(chengji))
chengji.remove(min(chengji))
print('最后得分%.2f' % (sum(chengji)/len(chengji)))
还有更好的整理例子,需要你自己去使用后才知道,尤其是多行的,更清晰。
补全信息的插件,见:
https://www.jianshu.com/p/d7f27ed94786