eric6/QScintilla/Editor.py

changeset 7785
9978016560ec
parent 7783
36f66ce496bd
child 7790
32b8db5a1fb4
--- a/eric6/QScintilla/Editor.py	Tue Oct 13 19:02:26 2020 +0200
+++ b/eric6/QScintilla/Editor.py	Wed Oct 14 17:50:39 2020 +0200
@@ -3083,8 +3083,8 @@
         try:
             with E5OverrideCursor():
                 if createIt and not os.path.exists(fn):
-                    f = open(fn, "w")
-                    f.close()
+                    with open(fn, "w"):
+                        pass
                 if encoding == "":
                     encoding = self.__getEditorConfig("DefaultEncoding",
                                                       nodefault=True)
@@ -6742,9 +6742,8 @@
             return  # user aborted
         
         try:
-            f = open(fname, "r", encoding="utf-8")
-            lines = f.readlines()
-            f.close()
+            with open(fname, "r", encoding="utf-8") as f:
+                lines = f.readlines()
         except IOError:
             E5MessageBox.critical(
                 self,
@@ -6803,10 +6802,9 @@
         fname = Utilities.toNativeSeparators(fname)
         
         try:
-            f = open(fname, "w", encoding="utf-8")
-            f.write("{0}{1}".format(name, "\n"))
-            f.write(self.macros[name].save())
-            f.close()
+            with open(fname, "w", encoding="utf-8") as f:
+                f.write("{0}{1}".format(name, "\n"))
+                f.write(self.macros[name].save())
         except IOError:
             E5MessageBox.critical(
                 self,

eric ide

mercurial