如何在子模块上处理Pylint未使用的导入消息?

时间:2017-10-04 09:01:46

标签: python pylint

我有这段代码:

import pyqtgraph as pg  # Short name cause pyqtgraph is looong
import pyqtgraph.exporters

# ... some code

pg.foo()
pg.exporters.ExportItem(blah)

现在pylint抱怨import pyqtgraph.exporters说它是未使用的导入。解决此警告的Pythonic或优雅解决方案是什么?

请注意,如果没有import pyqtgraph.exporters,则无法调用该子模块中的方法。

2 个答案:

答案 0 :(得分:2)

你可以这样做:

import pyqtgraph as pg  # Short name cause pyqtgraph is looong
import pyqtgraph.exporters  # pylint: disable=unused-import

# ... some code

pg.foo()
pg.exporters.ExportItem(blah)

防止pylint警告。

答案 1 :(得分:0)

这应该有效

import pyqtgraph as pg  # Short name cause pyqtgraph is looong
from pyqtgraph import exporters

# ... some code

pg.foo()
exporters.ExportItem(blah)