用python实现文件读取和内容替换

infile = open("D:/test.txt", "r")  #打开文件
outfile = open("D:/pp2.txt", "w") # 内容输出
for line in infile:  #按行读文件,可避免文件过大,内存消耗        
      outfile.write(line.replace('    ', '    '))#first is old ,second is new
infile.close()    #文件关闭
outfile.close()

 

posted on 2015-06-10 11:21  矮油~  阅读(4297)  评论(0编辑  收藏  举报

导航