【发布时间】:2022-01-16 23:35:44
【问题描述】:
我认为 Python 中正确的导入顺序是问题的第一个答案所描述的顺序:What's the correct way to sort Python `import x` and `from x import y` statements?
因此,这段代码应该是正确的:
import os
import time
import yaml
from collections import OrderedDict
from xtesting.core import testcase
但是,当我运行 Pylint 时,我得到:
C: 5, 0: standard import "from collections import OrderedDict" should be placed before "import yaml" (wrong-import-order)
所以我猜“yaml”不是标准库。那么正确的方法应该是这个(即使它更丑陋且可读性差)?
import os
import time
from collections import OrderedDict
import yaml
from xtesting.core import testcase
【问题讨论】:
-
yaml默认情况下不会出现,Pep 是一个建议,请使用您认为更符合您的代码库的任何内容。