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 

 

posted @ 2016-05-23 22:02  wswang  阅读(4703)  评论(0编辑  收藏  举报