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