How to read all files in one folder and apply a function over them in python?
问题 I would like to run a function over all files in one folder and create new files out of them. I have put the code for one file bellow. I would appreciate it if you kindly help me. def newfield2(infile,outfile): output = ["%s\t%s" %(item.strip(),2) for item in infile] outfile.write("\n".join(output)) outfile.close() return outfile infile = open("E:/SAGA/data/2006last/325125401.all","r") outfile = open("E:/SAGA/data/2006last/325125401_edit.all","r") I would like to change all the files in the