[docs] email.header examples

Filip Valder fvalder at redhat.com
Wed Mar 21 05:08:43 EDT 2018


Hi all.

I would like to request documentation changes for code examples in:
https://docs.python.org/2/library/email.header.html
https://docs.python.org/3/library/email.header.html

Please see below & change it as desired or discard completely if it is 
unwanted.

The main point is that people who are not familiar with mail headers format 
actually use otherwise working examples from the docs and they do not know 
that the headers would be formatted inappropriately (in Python 3).

The fix below is still not yet complete, as optimal would be adding: 
header_name='Subject' to the params when creating the Header. Still it (at 
least) covers the main/significant difference between the two Python versions.


For Python 2 - add .encode() method and the comment:
>>> msg['Subject'] = h
Change to:
>>> msg['Subject'] = h.encode()  # .encode() ensures same behavior when
>>>                              # porting code to Python 3


For Python 3 - just add the .encode() method:
>>> msg['Subject'] = h
Change to:
>>> msg['Subject'] = h.encode()


Regards, thank you,
Filip

-- 
Filip Valder
EMEA Software Engineer
+420 532 270 041
fvalder at redhat.com

Red Hat Czech
Purkyňova 71/99, 3080/97b, 647/111
612 00, Brno (CZ)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.png
Type: image/png
Size: 19649 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/docs/attachments/20180321/4617b7f5/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/docs/attachments/20180321/4617b7f5/attachment-0001.sig>


More information about the docs mailing list