Refactor file opening to use 'with' statement

This commit is contained in:
Nicolas Saillant 2024-06-12 09:30:23 +02:00
parent 3aa8e3ad73
commit b2e6a4abb0
1 changed files with 2 additions and 2 deletions

View File

@ -108,8 +108,8 @@ with open(input_report_file_name, "rt", encoding="utf-8") as input_report_file:
if not os.path.isdir(name):
is_ignored = True
os.mkdir(name)
report_file_handle=open("{dir}/{file}".format(dir=name, file=report_file_name), "w+", encoding="utf-8")
report_file_handle.write(open("{}/../../../../../.scm-branch".format(os.getcwd()), 'r', encoding="utf-8").read())
with open("{dir}/{file}".format(dir=name, file=report_file_name), "w+", encoding="utf-8") as report_file_handle:
report_file_handle.write(open("{}/../../../../../.scm-branch".format(os.getcwd()), 'r', encoding="utf-8").read())
else:
is_ignored = False
file_path = "{dir}/{file}".format(dir=name, file=report_file_name)