From 4b5988ef3b5990dd27611b0066ea5b977b41006a Mon Sep 17 00:00:00 2001 From: UP929312 <36114463+UP929312@users.noreply.github.com> Date: Thu, 9 Jun 2022 15:20:44 +0100 Subject: [PATCH] Cleanup with the use of context managers --- code/gentleScriptWriter.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/code/gentleScriptWriter.py b/code/gentleScriptWriter.py index 3167f51..59f44fb 100644 --- a/code/gentleScriptWriter.py +++ b/code/gentleScriptWriter.py @@ -7,12 +7,10 @@ args = parser.parse_args() INPUT_FILE = args.input_file -f = open(INPUT_FILE+".txt","r+") -script = f.read() -f.close() +with open(INPUT_FILE+".txt","r+") as f: + script = f.read() + +with open(INPUT_FILE+"_g.txt","w+") as f: + f.write(removeTags(script)) # This will automatically flush anyway -f = open(INPUT_FILE+"_g.txt","w+") -f.write(removeTags(script)) -f.flush() -f.close() print("Done creating the gentle-friendly script!")