3 Ways to Write Text to a File in Python
Posted andy_0212
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3 Ways to Write Text to a File in Python相关的知识,希望对你有一定的参考价值。
https://cmdlinetips.com/2012/09/three-ways-to-write-text-to-a-file-in-python/
1 with open("myOutFile.txt", "w") as outF: 2 for line in textList: 3 print(line, file=outF)
all_lines = [‘1‘, ‘2‘, ‘3‘]
with open("myOutFile.txt", "w") as outF: outF.writelines(all_lines)
with open(out_filename, ‘w‘) as out_file: .. .. .. parsed_line out_file.write(parsed_line)
以上是关于3 Ways to Write Text to a File in Python的主要内容,如果未能解决你的问题,请参考以下文章
[Python Cookbook] Pandas: 3 Ways to define a DataFrame
译3 ways to define a JavaScript class
3 Ways to Learn Whether a Windows Program is 64-bit or 32-bit