代码如下:
#!/usr/bin/env python
import time
start = time.time()
import glob
fp_out=open("count_matrix.csv", 'w')
fp_out.write("Sample"+","+"Length"+","+"Count")
for filename in glob.glob('*.txt'):
with open(filename, 'r') as fp:
for line in fp:
length = line.rstrip().split("\t")[0]
count = line.rstrip().split("\t")[1]
fp_out.write("\n"+filename[:-4]+","+length+","+count)
fp_out.close()
end = time.time()
print("used %s s" % str(end - start))
结果展示: