email.getaddresses()的输出不符合预期

时间:2014-03-23 15:46:00

标签: python python-3.3

根据email.getaddresses()模块的文档,我希望getaddresses('"John Doe" <johndoe@mail.com>')返回:

[('John Doe', 'johndoe@mail.com')]

但它返回的内容(在Python 3.3下)是:

  

[(&#39;&#39;,&#39;,J,o,h,n ,, D,o,e,&#39;),(&#39;&#39;, &#39;&#39;),(&#39;&#39;,&#39;&#39;),(&#39;&#39;,&#39; j&#39;), (&#39;&#39;,&#39; o&#39;),(&#39;&#39;,&#39; h&#39;),(&#39;&#39;, &#39; n&#39;),(&#39;&#39;,&#39; d&#39;),(&#39;&#39;,&#39; o&#39;), (&#39;&#39;,&#39;),(&#39;&#39;,&#39; @&#39;),(&#39;&#39; ,&#39; m&#39;),(&#39;&#39;,&#39; a&#39;),(&#39;&#39;,&#39;我&#39;) ,(&#39;&#39;,&#39; l&#39;),(&#39;&#39;,&#39;。&#39;),(&#39;&#39; ;&#39; c&#39;),(&#39;&#39;,&#39; o&#39;),(&#39;&#39;,&#39; m&#39; ),(&#39;&#39;,&#39;&#39;)]

这不是最有用的。

是什么给出了?

1 个答案:

答案 0 :(得分:0)

根据email.utils.getaddresses documentation,参数应为标题字段值序列,而不是单个字符串。

>>> import email.utils
>>> email.utils.getaddresses(['"John Doe" <johndoe@mail.com>'])
[('John Doe', 'johndoe@mail.com')]