Commits

Éric Araujo committed 7af576e Merge

Merge #12295 fix from 3.2

Comments (0)

Files changed (1)

Lib/idlelib/textView.py

 
 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__':