summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/IOBinding.py
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2013-08-04 19:39:32 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2013-08-04 19:39:32 (GMT)
commitec53111f76ecba0dacb1a66acca465481303a524 (patch)
tree6255342788e83b2a9517f7956cc61ce5c5738b10 /Lib/idlelib/IOBinding.py
parent44473f26deaa7c524a674f5e3a68a34d30488166 (diff)
parent95f34ab95959fa67d258043622744dae8519c5b2 (diff)
downloadcpython-ec53111f76ecba0dacb1a66acca465481303a524.zip
cpython-ec53111f76ecba0dacb1a66acca465481303a524.tar.gz
cpython-ec53111f76ecba0dacb1a66acca465481303a524.tar.bz2
Merge with 3.3
Diffstat (limited to 'Lib/idlelib/IOBinding.py')
-rw-r--r--Lib/idlelib/IOBinding.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py
index dda3634..203b009 100644
--- a/Lib/idlelib/IOBinding.py
+++ b/Lib/idlelib/IOBinding.py
@@ -208,11 +208,10 @@ class IOBinding:
try:
# open the file in binary mode so that we can handle
# end-of-line convention ourselves.
- f = open(filename,'rb')
- two_lines = f.readline() + f.readline()
- f.seek(0)
- bytes = f.read()
- f.close()
+ with open(filename, 'rb') as f:
+ two_lines = f.readline() + f.readline()
+ f.seek(0)
+ bytes = f.read()
except OSError as msg:
tkMessageBox.showerror("I/O Error", str(msg), master=self.text)
return False
@@ -373,10 +372,8 @@ class IOBinding:
text = text.replace("\n", self.eol_convention)
chars = self.encode(text)
try:
- f = open(filename, "wb")
- f.write(chars)
- f.flush()
- f.close()
+ with open(filename, "wb") as f:
+ f.write(chars)
return True
except OSError as msg:
tkMessageBox.showerror("I/O Error", str(msg),