--- a/eric6/Utilities/__init__.py Tue Oct 13 19:02:26 2020 +0200 +++ b/eric6/Utilities/__init__.py Wed Oct 14 17:50:39 2020 +0200 @@ -171,9 +171,8 @@ @param filename name of the file to read (string) @return tuple of decoded text and encoding (string, string) """ - f = open(filename, "rb") - text = f.read() - f.close() + with open(filename, "rb") as f: + text = f.read() return decode(text) @@ -186,9 +185,8 @@ @return tuple of decoded text, encoding and hash value (string, string, string) """ - f = open(filename, "rb") - text = f.read() - f.close() + with open(filename, "rb") as f: + text = f.read() hashStr = str(QCryptographicHash.hash( QByteArray(text), QCryptographicHash.Md5).toHex(), encoding="ASCII") return decode(text) + (hashStr, ) @@ -269,9 +267,8 @@ @keyparam encoding encoding to be used to read the file (string) @return tuple of decoded text and encoding (string, string) """ - f = open(filename, "rb") - text = f.read() - f.close() + with open(filename, "rb") as f: + text = f.read() if encoding: try: return str(text, encoding), '{0}-selected'.format(encoding) @@ -307,9 +304,8 @@ """ etext, encoding = encode(text, origEncoding, forcedEncoding=forcedEncoding) - f = open(filename, "wb") - f.write(etext) - f.close() + with open(filename, "wb") as f: + f.write(etext) return encoding @@ -2041,9 +2037,8 @@ info.append("Distribution Info:") for rfile in releaseList: try: - f = open(rfile, "r") - lines = f.read().splitlines() - f.close + with open(rfile, "r") as f: + lines = f.read().splitlines() except IOError: continue