This code works but I want to close opened files. How to change this code ?
with open(output_file, "w", newline='') as f_output:
try:
os.remove(output_file) # Delete old file
except OSError:
pass
for r in range(len(new_list)):
open(output_file, "a").writelines(str(second_list[r] + '\n'))