save_report(path, lines) that writes each string from lines to the file at path, one per line, overwriting any existing content. Every line in the file must end with a newline character.save_report('report.txt', ['sales: 90', 'cost: 40'])file contains 'sales: 90\ncost: 40\n'
Mode 'w' truncates and rewrites the file.
f.write(line + '\n') in a loop, or f.writelines with a generator.
The with block handles closing.