summaryrefslogtreecommitdiffstats
path: root/Doc/includes/email-simple.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-02-25 16:14:09 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-02-25 16:14:09 (GMT)
commitf9e3cf1f9f6eaefba19593783e1cdf7681d1fa65 (patch)
treecbaa625efe90eefd38a96cc7577e2d28b135cae0 /Doc/includes/email-simple.py
parentb808d590a24066bc03d21b55ed5e890a012477a8 (diff)
downloadcpython-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-simple.py')
-rw-r--r--Doc/includes/email-simple.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/Doc/includes/email-simple.py b/Doc/includes/email-simple.py
index 077568d..b9b8b41 100644
--- a/Doc/includes/email-simple.py
+++ b/Doc/includes/email-simple.py
@@ -6,10 +6,9 @@ from email.mime.text import MIMEText
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
-fp = open(textfile, 'rb')
-# Create a text/plain message
-msg = MIMEText(fp.read())
-fp.close()
+with open(textfile) as fp:
+ # Create a text/plain message
+ msg = MIMEText(fp.read())
# me == the sender's email address
# you == the recipient's email address