diff --git a/flow/util/genMetrics.py b/flow/util/genMetrics.py index 938a4c91fb..e112cd1d2d 100755 --- a/flow/util/genMetrics.py +++ b/flow/util/genMetrics.py @@ -142,17 +142,14 @@ def extractGnuTime(prefix, jsonFile, file): # def read_sdc(file_name): clkList = [] - sdcFile = None try: - sdcFile = open(file_name, "r") - except IOError: - print("[WARN] Failed to open file:", file_name) + with open(file_name, "r") as sdcFile: + lines = sdcFile.readlines() + except OSError as e: + print(f"[WARN] Failed to open file: {file_name} ({e})") return clkList - lines = sdcFile.readlines() - sdcFile.close() - for line in lines: if len(line.split()) < 2: continue @@ -185,10 +182,9 @@ def is_git_repo(folder=None): def merge_jsons(root_path, output, files): paths = sorted(glob(os.path.join(root_path, files))) for path in paths: - file = open(path, "r") - data = json.load(file) + with open(path, "r") as file: + data = json.load(file) output.update(data) - file.close() def extract_metrics(