summaryrefslogtreecommitdiff
path: root/Lib/idlelib/IOBinding.py
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2013-08-04 15:39:03 -0400
committerTerry Jan Reedy <tjreedy@udel.edu>2013-08-04 15:39:03 -0400
commit95f34ab95959fa67d258043622744dae8519c5b2 (patch)
tree3fbbe3a8bf381438abfc71fd5613e883b55dc4cf /Lib/idlelib/IOBinding.py
parentc86d7e989c98d57449263201e826a52c15102a64 (diff)
downloadcpython-git-95f34ab95959fa67d258043622744dae8519c5b2.tar.gz
Issue #18151: Replace remaining Idle 'open...close' pairs with 'with open'.
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 37a11ad6ad..4558ae6c37 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),