diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2015-02-25 16:14:09 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2015-02-25 16:14:09 (GMT) |
commit | f9e3cf1f9f6eaefba19593783e1cdf7681d1fa65 (patch) | |
tree | cbaa625efe90eefd38a96cc7577e2d28b135cae0 /Doc/includes/email-read-alternative-new-api.py | |
parent | b808d590a24066bc03d21b55ed5e890a012477a8 (diff) | |
download | cpython-f9e3cf1f9f6eaefba19593783e1cdf7681d1fa65.zip cpython-f9e3cf1f9f6eaefba19593783e1cdf7681d1fa65.tar.gz cpython-f9e3cf1f9f6eaefba19593783e1cdf7681d1fa65.tar.bz2 |
Issue #23511: Port email-simple.py to Python 3.
Also, update email examples to use the context manager version of open().
Patch by Baptiste Mispelon.
Diffstat (limited to 'Doc/includes/email-read-alternative-new-api.py')
-rw-r--r-- | Doc/includes/email-read-alternative-new-api.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Doc/includes/email-read-alternative-new-api.py b/Doc/includes/email-read-alternative-new-api.py index 8ab4e9f..3f5ab24 100644 --- a/Doc/includes/email-read-alternative-new-api.py +++ b/Doc/includes/email-read-alternative-new-api.py @@ -12,7 +12,8 @@ from email.parser import BytesParser from imaginary import magic_html_parser # In a real program you'd get the filename from the arguments. -msg = BytesParser(policy=policy.default).parse(open('outgoing.msg', 'rb')) +with open('outgoing.msg', 'rb') as fp: + msg = BytesParser(policy=policy.default).parse(fp) # Now the header items can be accessed as a dictionary, and any non-ASCII will # be converted to unicode: |