python中isort的使用

是一个使import 列表更美观的工具包,官方例子如下:

before

from my_lib import Object

print("Hey")

import os

from my_lib import Object3

from my_lib import Object2

import sys

from third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14

import sys

from __future__ import absolute_import

from third_party import lib3

print("yo")

 after

from __future__ import absolute_import

import os
import sys

from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8,
                         lib9, lib10, lib11, lib12, lib13, lib14, lib15)

from my_lib import Object, Object2, Object3

print("Hey")
print("yo")

 

 

Using isort

From the command line:

isort mypythonfile.py mypythonfile2.py

or recursively:

isort -rc .

which is equivalent to:

isort **/*.py

or to see the proposed changes without applying them:

isort mypythonfile.py --diff

Finally, to atomically run isort against a project, only applying changes if they don't introduce syntax errors do:

isort -rc --atomic .



懒得翻译了,很简单,大家自己看吧。。。。


参考链接:
https://github.com/timothycrosley/isort

 

 

个人实践的例子如下,写个test.py

from sys import argv
import os

执行

isort test.py

之后就变成了

import os
from sys import argv

 2333333333 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值