From ccf03a1cdcf1f108ca41b4f60821de40c1b695e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Mon, 1 Aug 2011 17:29:36 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20resource=20warning=20when=20looking=20at?= =?UTF-8?q?=20turtledemo=E2=80=99s=20help=20(#12295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/idlelib/textView.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/idlelib/textView.py b/Lib/idlelib/textView.py index e5c551ad83a..e0f49d4c450 100644 --- a/Lib/idlelib/textView.py +++ b/Lib/idlelib/textView.py @@ -62,14 +62,15 @@ def view_text(parent, title, text): def view_file(parent, title, filename, encoding=None): try: - textFile = open(filename, 'r', encoding=encoding) + with open(filename, 'r', encoding=encoding) as file: + contents = file.read() except IOError: import tkinter.messagebox as tkMessageBox tkMessageBox.showerror(title='File Load Error', message='Unable to load file %r .' % filename, parent=parent) else: - return view_text(parent, title, textFile.read()) + return view_text(parent, title, contents) if __name__ == '__main__':