python .txt文件奇数偶数行分开保存

def fenhang(infile,outfile,outfile1):
 
 infopen = open(infile,'r',encoding='utf-8')
 outopen = open(outfile,'w',encoding='utf-8')
 outopen1 = open(outfile1, 'w', encoding='utf-8')
 lines = infopen.readlines()
 i = 0
 for line in lines:
  i += 1
  if i % 2 == 0:
      outopen.write(line)
  else:
      outopen1.write(line)

 infopen.close()
 outopen.close()

if __name__=="__main__":
    infile='/Wnt/Wnt_proteinB.txt'
    outfile='/Wnt/Wnt_proteinBBBB.txt'  ####偶数行
    outfile1='/Wnt_proteinnameB.txt'    ####奇数行
    
    fenhang(infile,outfile,outfile1)

上一篇:Mybatis记录


下一篇:我提交的一个内核补丁—CFS的child-runs-first