pylint not recognizing some of the standard library

为君一笑 提交于 2021-02-06 15:15:52

问题


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?


回答1:


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 to email's playing with import tricks).




回答2:


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.

from email import Message
from email import Header
from email.MIMEText import MIMEText

should be

from email.message import Message
from email.header import Header
from email.mime.text import MIMEText

etc.




回答3:


The email module uses some horrible import hackery, which has bitten me in the past. You can do this:

>>> from email import Message

but you can't do this:

>>> import email
>>> email.Message
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'Message'

I realise that's not very helpful for making pylint work, but it might help to explain the problem.



来源:https://stackoverflow.com/questions/1316334/pylint-not-recognizing-some-of-the-standard-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!