From 27b956595201f8d1e2f409061c928d5408ad8780 Mon Sep 17 00:00:00 2001 From: elliotwutingfeng Date: Fri, 18 Feb 2022 22:32:06 +0800 Subject: [PATCH] Use context manager when opening config.json --- download.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/download.py b/download.py index 976e68d..9034c2f 100644 --- a/download.py +++ b/download.py @@ -16,9 +16,8 @@ config_data = os.environ['CZDS_CONFIG'] config = json.loads(config_data) else: - config_file = open("config.json", "r") - config = json.load(config_file) - config_file.close() + with open("config.json", "r") as config_file: + config = json.load(config_file) except: sys.stderr.write("Error loading config.json file.\n") exit(1)