#!/usr/bin/env python
# -*- coding:utf-8 -*-

file="/usr/local/test"
       
alist = ["hello\n","python\n"]
generator = ("{}\t{}\n".format(i,i+1) for i in range(9)) 

#写入文件 with open(file,"w") as fd_out: fd_out.writelines(alist) fd_out.writelines(generator) #读文件 with open(file,"r") as fd_in: for line in fd_in: print(line.strip())

  

 

 posted on 2020-08-05 00:21  boye169  阅读(90)  评论(0编辑  收藏  举报