首页 > 编程语言 > 详细

python中isort的使用

时间:2016-05-23 22:43:29      阅读:261      评论:0      收藏:0      [点我收藏+]

是一个使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 

 

python中isort的使用

原文:http://www.cnblogs.com/wswang/p/5521595.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!