Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccf03a1

Browse files
committed
Fix resource warning when looking at turtledemo’s help (#12295)
1 parent 2ffea0e commit ccf03a1

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Lib/idlelib/textView.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ def view_text(parent, title, text):
6262

6363
def view_file(parent, title, filename, encoding=None):
6464
try:
65-
textFile = open(filename, 'r', encoding=encoding)
65+
with open(filename, 'r', encoding=encoding) as file:
66+
contents = file.read()
6667
except IOError:
6768
import tkinter.messagebox as tkMessageBox
6869
tkMessageBox.showerror(title='File Load Error',
6970
message='Unable to load file %r .' % filename,
7071
parent=parent)
7172
else:
72-
return view_text(parent, title, textFile.read())
73+
return view_text(parent, title, contents)
7374

7475

7576
if __name__ == '__main__':

0 commit comments

Comments
 (0)