Import order coding standard

PEP8 suggests that:

Imports should be grouped in the following order:

  1. standard library imports
  2. related third party imports
  3. local application/library specific imports

You should put a blank line between each group of imports.

Is there a way to check if the standard is violated anywhere in the package using static code analysis tools, like pylint, pyflakes, pychecker, pep8?

Example of violation:

    from my_package import my_module
    from django.db import models
    import os

Correct way to import:

    import os

    from django.db import models

    from my_package import my_module

The current version of pylint now does this, and reports it as error class C0411.

From: stackoverflow.com/q/22722976

Back to homepage or read more recommendations: