eric6/VirtualEnv/VirtualenvExecDialog.py

changeset 7785
9978016560ec
parent 7781
607a6098cb44
child 7836
2f0d208b8137
--- a/eric6/VirtualEnv/VirtualenvExecDialog.py	Tue Oct 13 19:02:26 2020 +0200
+++ b/eric6/VirtualEnv/VirtualenvExecDialog.py	Wed Oct 14 17:50:39 2020 +0200
@@ -260,15 +260,14 @@
                          .format(logFile))
         
         try:
-            f = open(logFile, "w", encoding="utf-8")
-            f.write(self.tr("Output:\n"))
-            f.write(outtxt)
-            errtxt = self.errors.toPlainText()
-            if errtxt:
-                f.write("\n")
-                f.write(self.tr("Errors:\n"))
-                f.write(errtxt)
-            f.close()
+            with open(logFile, "w", encoding="utf-8") as f:
+                f.write(self.tr("Output:\n"))
+                f.write(outtxt)
+                errtxt = self.errors.toPlainText()
+                if errtxt:
+                    f.write("\n")
+                    f.write(self.tr("Errors:\n"))
+                    f.write(errtxt)
         except (IOError, OSError) as err:
             self.__logError(
                 self.tr("""The logfile '{0}' could not be written.\n"""
@@ -294,9 +293,8 @@
                          .format(script))
         
         try:
-            f = open(script, "w", encoding="utf-8")
-            f.write(txt)
-            f.close()
+            with open(script, "w", encoding="utf-8") as f:
+                f.write(txt)
         except (IOError, OSError) as err:
             self.__logError(
                 self.tr("""The script file '{0}' could not be written.\n"""

eric ide

mercurial