From d008e084a21dc6a5118f947c5e6e429e92e6ba7f Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Mon, 26 Sep 2022 14:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao Change-Id: I8e10789dca94bef1390f13a4f6f53ba63e9b29cf --- 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