pylint 无法识别某些标准库
我正在使用 pylint + pydev,以及 python 2.6。 我有一个只有这行代码的模块
from email import Message
现在,当我尝试运行该模块时,它运行良好。但是pylint报错:
ID: E0611 No name 'Message' in module 'email'
虽然它存在... 知道为什么吗?
I'm using pylint + pydev, with python 2.6.
I have a module with just this line of code
from email import Message
Now when I try to run this module it runs fine. But pylint reports an error:
ID: E0611 No name 'Message' in module 'email'
Although it exists...
Any idea why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
意识到这是一个老问题,但正确的答案是,调用您需要的内容的旧方法(使用 Richie 描述的“导入黑客”)早已被弃用(尽管仍然出现在许多教程中)。如果您使用新方法,您将编写更好的代码,并且
pylint
不会抱怨。例如
应该是
等等。
realise this is an old question, but the correct answer is that the older ways of invoking what you need, which use the "import hackery" that Richie describes, have long been deprecated (despite still appearing in many tutorials). If you use the new ways, you'll be writing better code and
pylint
won't complain.e.g.
should be
etc.
我喜欢 pylint,但我确实发现我必须使用很多
# pylint:disable-msg=E0611
之类的东西来让它在完全正确但令人困惑的情况下关闭(例如,就像在本例中一样,由于email
使用了导入技巧)。I like pylint, but I do find I have to use a lot of
# pylint: disable-msg=E0611
and the like to make it shut up in cases that are perfectly correct but confuse it (for example, like in this case, due toemail
's playing with import tricks).email
模块使用了一些可怕的导入黑客技术,这在过去曾困扰过我。你可以这样做:但你不能这样做:
我意识到这对于使 pylint 工作不是很有帮助,但它可能有助于解释问题。
The
email
module uses some horrible import hackery, which has bitten me in the past. You can do this:but you can't do this:
I realise that's not very helpful for making pylint work, but it might help to explain the problem.