diff -r 3257703e10c5 -r 9978016560ec eric6/Project/Project.py --- a/eric6/Project/Project.py Tue Oct 13 19:02:26 2020 +0200 +++ b/eric6/Project/Project.py Wed Oct 14 17:50:39 2020 +0200 @@ -2351,8 +2351,8 @@ "Python3", "MicroPython" ]: fn = os.path.join(self.ppath, "__init__.py") - f = open(fn, "w", encoding="utf-8") - f.close() + with open(fn, "w", encoding="utf-8"): + pass self.appendFile(fn, True) # create an empty main script file, if a name was given @@ -2362,8 +2362,8 @@ self.ppath, self.pdata["MAINSCRIPT"]) else: ms = self.pdata["MAINSCRIPT"] - f = open(ms, "w") - f.close() + with open(ms, "w"): + pass self.appendFile(ms, True) if self.pdata["MAKEPARAMS"]["MakeEnabled"]: @@ -2373,8 +2373,8 @@ mf = os.path.join(self.ppath, mf) else: mf = os.path.join(self.ppath, Project.DefaultMakefile) - f = open(mf, "w") - f.close() + with open(mf, "w"): + pass self.appendFile(mf) tpd = os.path.join(self.ppath, self.translationsRoot) @@ -2415,8 +2415,8 @@ ms = self.pdata["MAINSCRIPT"] if not os.path.exists(ms): try: - f = open(ms, "w") - f.close() + with open(ms, "w"): + pass except EnvironmentError as err: E5MessageBox.critical( self.ui, @@ -2438,8 +2438,8 @@ mf = os.path.join(self.ppath, Project.DefaultMakefile) if not os.path.exists(mf): try: - f = open(mf, "w") - f.close() + with open(mf, "w"): + pass except EnvironmentError as err: E5MessageBox.critical( self.ui, @@ -2466,8 +2466,8 @@ ]: fn = os.path.join(self.ppath, "__init__.py") if not os.path.exists(fn): - f = open(fn, "w", encoding="utf-8") - f.close() + with open(fn, "w", encoding="utf-8"): + pass self.appendFile(fn, True) self.saveProject() @@ -2729,8 +2729,8 @@ mf = os.path.join(self.ppath, Project.DefaultMakefile) if not os.path.exists(mf): try: - f = open(mf, "w") - f.close() + with open(mf, "w"): + pass except EnvironmentError as err: E5MessageBox.critical( self.ui, @@ -5269,12 +5269,14 @@ newline = None else: newline = self.getEolString() - pkglistFile = open(pkglist, "w", encoding="utf-8", newline=newline) - pkglistFile.write("\n".join(header) + "\n") - pkglistFile.write( - "\n".join([Utilities.fromNativeSeparators(f) for f in lst])) - pkglistFile.write("\n") # ensure the file ends with an empty line - pkglistFile.close() + with open(pkglist, "w", encoding="utf-8", + newline=newline) as pkglistFile: + pkglistFile.write("\n".join(header) + "\n") + pkglistFile.write( + "\n".join([Utilities.fromNativeSeparators(f) + for f in lst])) + pkglistFile.write("\n") + # ensure the file ends with an empty line except IOError as why: E5MessageBox.critical( self.ui, @@ -5340,9 +5342,8 @@ break try: - pkglistFile = open(pkglist, "r", encoding="utf-8") - names = pkglistFile.read() - pkglistFile.close() + with open(pkglist, "r", encoding="utf-8") as pkglistFile: + names = pkglistFile.read() except IOError as why: E5MessageBox.critical( self.ui,