知识卡片
普通字典会压缩重复邮件头
邮件头可以重复,直接把items转成以头名为键的普通字典会覆盖同名项,丢掉多值信息。需要保留多个Received等字段时,应使用支持多值的表示或逐项保留;消息对象的映射接口也有大小写与重复值语义,不能未经说明当成普通字典。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 2 处
- · 查看原书依据
o_msg = dict([ (k, v) for (k,v) in msg.items() ]) # Assume one part to the message and get its content # and its content type part = [p for p in msg.walk()][0] o_msg['contentType']
- · 查看原书依据
for (k, v) in msg.items(): json_msg[k] = v.decode('utf-8', 'ignore') # The To, Cc, and Bcc fields, if present, could have multiple items. # Note that not all of these fields are ne
参考来源
- 位置:《社交网站的数据挖掘与分析(原书第2版)》第6章《6.2.1 Unix邮箱指南》(spine102;extracted/OReilly精品图书系列共21册(《Javascript权威指南》、《机器学习:实用案例解析》、《编写可读代码的艺术》、《算法精解》等)/_epub-src/text/part0091.html;u089-ch06-006)。
- 结论依据:原文在“o_msg = dict”附近的定义、例子或代码支撑本卡核心说明:邮件头可以重复,直接把items转成以头名为键的普通字典会覆盖同名项,丢掉多值信息。边界按已读前提解释;示例未执行。
- 原始内容:o_msg = dict([ (k, v) for (k,v) in msg.items() ]) # Assume one part to the message and get its content # and its content type part = [p for p in msg.walk()][0] o_msg['contentType']
- 位置:《社交网站的数据挖掘与分析(原书第2版)》第6章《6.2.4 将Unix邮箱转换为JSON》(spine102;extracted/OReilly精品图书系列共21册(《Javascript权威指南》、《机器学习:实用案例解析》、《编写可读代码的艺术》、《算法精解》等)/_epub-src/text/part0091.html;u092-ch06-006)。
- 结论依据:本次JSON化仍逐键覆盖重复头,健壮性不能只看多部件和日期转换。
- 原始内容:for (k, v) in msg.items(): json_msg[k] = v.decode('utf-8', 'ignore') # The To, Cc, and Bcc fields, if present, could have multiple items. # Note that not all of these fields are ne