What's the correct way to sort Python `import x` and `from x import y` statements?

后端 未结 6 1245
半阙折子戏
半阙折子戏 2020-12-04 05:32

The python style guide suggests to group imports like this:

Imports should be grouped in the following order:

  1. standard library imp
6条回答
  •  没有蜡笔的小新
    2020-12-04 06:04

    According to the CIA's internal coding conventions (part of the WikiLeaks Vault 7 leak), python imports should be grouped into three groups:

    1. Standard library imports
    2. Third-party imports
    3. Application-specific imports

    Imports should be ordered lexicographically within these groups, ignoring case:

    import foo
    from foo import bar
    from foo.bar import baz
    from foo.bar import Quux
    from Foob import ar
    

提交回复
热议问题