Nov-04-2017, 04:16 PM
Use code tag BBcode help,use
Ctrl+Shift+v
when copy in to preserve indentation.with open('data.txt') as f,open('new.txt', 'w') as f_out: lst = [i.strip() for i in f] lst.append('test 4') f_out.write('\n'.join(lst))To append to existing file.
with open('data.txt', 'a') as f: f.write('test 4\n')