summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-08-01 15:29:36 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-08-01 15:29:36 (GMT)
commitccf03a1cdcf1f108ca41b4f60821de40c1b695e2 (patch)
treecd10b1a592cb92ea4addcba740c11eaf4d821f88 /Lib/idlelib
parent2ffea0e8d7f93675e60a3afd85d0f7f8861a8978 (diff)
downloadcpython-ccf03a1cdcf1f108ca41b4f60821de40c1b695e2.zip
cpython-ccf03a1cdcf1f108ca41b4f60821de40c1b695e2.tar.gz
cpython-ccf03a1cdcf1f108ca41b4f60821de40c1b695e2.tar.bz2
Fix resource warning when looking at turtledemo’s help (#12295)
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/textView.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/idlelib/textView.py b/Lib/idlelib/textView.py
index e5c551a..e0f49d4 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__':