《文件操作-open》

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

file="/usr/local/test"
       
alist = ["hello
","python
"]
generator = ("{}	{}
".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())

  

原文地址:https://www.cnblogs.com/boye169/p/13437231.html