lines = ['line1', 'line2'] with open('filename.txt', 'w') as f: f.writelines("%s " % l for l in lines)
fw.write(' '.join(line_list) + ' ')