From 6fc99e72a6d37354317243cf1c908cb1d3fa0fb8 Mon Sep 17 00:00:00 2001 From: anonymousdouble <112695649+anonymousdouble@users.noreply.github.com> Date: Mon, 1 Jan 2024 19:49:06 +1100 Subject: [PATCH] Update common.py refactor with With statement to open file to make code more Pythonic --- datadog/dogshell/common.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/datadog/dogshell/common.py b/datadog/dogshell/common.py index 251e6582b..65003476c 100644 --- a/datadog/dogshell/common.py +++ b/datadog/dogshell/common.py @@ -98,10 +98,9 @@ def load(self, config_file, api_key, app_key, api_host): config.set("Connection", "apikey", api_key) config.set("Connection", "appkey", app_key) - f = open(config_file, "w") - config.write(f) - f.close() - print("Wrote %s" % config_file) + with open(config_file, "w") as f: + config.write(f) + print("Wrote %s" % config_file) elif response.strip().lower() == "n": # Abort print_err("Exiting\n")