How to read and write multiple files?

后端 未结 8 1183
南方客
南方客 2020-12-24 00:52

I want to write a program for this: In a folder I have n number of files; first read one file and perform some operation then store result in a separate file. Then

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 01:07

    from pylab import * 
    import csv 
    import os 
    import glob 
    import re 
    x=[] 
    y=[]
    
    f=open("one.txt",'w')
    
    for infile in glob.glob(('*.csv')):
        #   print "" +infile
        csv23=csv2rec(""+infile,'rb',delimiter=',')
        for line in csv23:      
            x.append(line[1])
            #  print len(x)
        for i in range(3000,8000):
            y.append(x[i])
        print ""+infile,"\t",mean(y)
        print >>f,""+infile,"\t\t",mean(y)
        del y[:len(y)]
        del x[:len(x)]
    

提交回复
热议问题