VS Code / Pylint:“第三方导入[x]应放在[y]之前”

时间:2018-06-12 12:22:39

标签: python visual-studio-code pylint

Pylint喜欢抱怨这些导入的订单

from __future__ import print_function   # for improved print func
import logging, sys, configparser, datetime, pyodbc
from appJar import gui                  # testing GUI...

这导致:

C0411:third party import "from appJar import gui" should be placed before "import logging, sys, configparser, datetime, pyodbc"

然而,无论这些是如何重新排列的,pylint总是抱怨某些东西需要先于别的东西。即,:

示例2

from appJar import gui                  # testing GUI...
from __future__ import print_function   # for improved print func
import logging, sys, configparser, datetime, pyodbc

结果:

C0411:standard import "from __future__ import print_function" should be placed before "from appJar import gui (50,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (51,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (51,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (51,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (51,1)"

示例3

from __future__ import print_function   # for improved print func

from appJar import gui                  # testing GUI...

import logging, sys, configparser, datetime, pyodbc

结果:

C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (53,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (53,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (53,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (53,1)"

间距似乎并不重要。关于如何写这个的任何想法?谢谢。

1 个答案:

答案 0 :(得分:1)

问题来自于这一行:

import itertools
from itertools import *
from importlib import reload

itools = reload(itertools)

for k, v in itools.__dict__.items():
    if k in globals():
            globals()[k] = v

从标准Python库(import logging, sys, configparser, datetime, pyodbc syslogging ...)和第三方库(datetime)中导入。

由于标准进口应该在第三方进口和第三方进口通常按字母顺序排列之前进行,因此同一行中的标准和第三方进口混合可能是这些错误背后的原因。