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)

 

posted @ 2019-10-18 15:16  andy_0212  阅读(163)  评论(0编辑  收藏  举报