with open('/path/to/filename.txt', mode='wt', encoding='utf-8') as myfile: myfile.write(' '.join(lines))