python – flake8:import语句的顺序错误

PEP8表明:

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.

我正在为lint Python文件使用Flake8Lint Sublime Text插件.

我的代码如下:

import logging
import re
import time
import urllib
import urlparse

from flask import Blueprint
from flask import redirect
from flask import request
from flask.ext.login import current_user
from flask.ext.login import login_required

from my_application import one_module

它会显示如下警告:

import statements are in the wrong order, from my_application should be before from from flask.ext.login.

但是flask是第三方库,它应该在我的my_application导入之前.这就是为什么?怎么解决?

最佳答案 flake8-import-order插件需要为
configured才能知道应该将哪些名称视为应用程序的本地名称.

对于您的示例,如果在程序包根目录中使用.flake8 ini文件,则它应包含:

[flake8]
application_import_names = my_application

或者,您只能使用应用程序本地导入的相对导入:

from __future__ import absolute_import

import os
import sys

import requests

from . import (
    client
)


...
点赞