码迷,mamicode.com
首页 > 编程语言 > 详细

3 Ways to Write Text to a File in Python

时间:2019-10-18 16:14:37      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:lines   print   class   text   line   pen   code   with open   file   

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

标签:lines   print   class   text   line   pen   code   with open   file   

原文地址:https://www.cnblogs.com/andy-0212/p/11698444.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!