mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #18151: Replace remaining Idle 'open...close' pairs with 'with open'.
This commit is contained in:
parent
c86d7e989c
commit
95f34ab959
3 changed files with 10 additions and 17 deletions
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue