python sublime 怎么样使代码更整齐

使用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值