diff -r 1b4772ab420f Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py Sun Aug 04 01:05:02 2013 +0300 +++ b/Lib/idlelib/EditorWindow.py Sun Aug 04 11:04:14 2013 +0300 @@ -882,12 +882,9 @@ "Load and update the recent files list and menus" rf_list = [] if os.path.exists(self.recent_files_path): - rf_list_file = open(self.recent_files_path,'r', - encoding='utf_8', errors='replace') - try: + with open(self.recent_files_path, 'r', + encoding='utf_8', errors='replace') as rf_list_file: rf_list = rf_list_file.readlines() - finally: - rf_list_file.close() if new_file: new_file = os.path.abspath(new_file) + '\n' if new_file in rf_list: diff -r 1b4772ab420f Lib/idlelib/IOBinding.py --- a/Lib/idlelib/IOBinding.py Sun Aug 04 01:05:02 2013 +0300 +++ b/Lib/idlelib/IOBinding.py Sun Aug 04 11:04:14 2013 +0300 @@ -208,11 +208,10 @@ 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 @@ 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), diff -r 1b4772ab420f Lib/idlelib/ScriptBinding.py --- a/Lib/idlelib/ScriptBinding.py Sun Aug 04 01:05:02 2013 +0300 +++ b/Lib/idlelib/ScriptBinding.py Sun Aug 04 11:04:14 2013 +0300 @@ -87,9 +87,8 @@ self.shell = shell = self.flist.open_shell() saved_stream = shell.get_warning_stream() shell.set_warning_stream(shell.stderr) - f = open(filename, 'rb') - source = f.read() - f.close() + with open(filename, 'rb') as f: + source = f.read() if b'\r' in source: source = source.replace(b'\r\n', b'\n') source = source.replace(b'\r', b'\n')