PEP8 suggests that:
Imports should be grouped in the following order:
- standard library imports
- related third party imports
- 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.