From 45e824f5e701962e20c2f2ef6643f1c2b0123fa0 Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Mon, 26 Sep 2022 12:56:05 +0800 Subject: [PATCH] change open to with open Signed-off-by: aodongbiao Change-Id: I9d2f6ad94180ed79778228679d386e0d03f89fef --- tools/syscap_check.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/syscap_check.py b/tools/syscap_check.py index a4932aa..e2b97fa 100644 --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -78,15 +78,15 @@ def read_value_from_json(filepath: str, if not os.path.isfile(filepath): print('error: "{}" is not a file.') return - f = open(filepath, 'r') - data = json.load(f) - for key in key_hierarchy: - try: - data = data[key] - except KeyError: - return - finally: - f.close() + with open(filepath, 'r', encoding='utf-8') as f: + data = json.load(f) + for key in key_hierarchy: + try: + data = data[key] + except KeyError: + return + finally: + pass data = [post_handler(x) for x in data if len(x) != 0 and not x.isspace()] if len(data) != 0: result_dict[filepath] = data -- Gitee