import linecache
import docx
import re
import numpy as np
#count = linecache.getline("C:\\Users\\admin\\Desktop\\470_0.003.txt",4)
list=[]
#a=len(open(r"C:\\Users\\admin\\Desktop\\470_0.003.txt",'rU').readlines())
#a=len(open(r"C:\\Users\\admin\\Desktop\\0_doppler.txt",'rU').readlines())
#a=len(open(r"C:\\Users\\admin\\Desktop\\470_3_1410_1880.txt",'rU').readlines())
a=len(open(r"C:\\Users\\admin\\Desktop\\5_different.txt",'rU').readlines())
i=2
while(i<a):
#str=linecache.getline("C:\\Users\\admin\\Desktop\\470_0.003.txt",i)
#str = linecache.getline("C:\\Users\\admin\\Desktop\\0_doppler.txt", i)
#str = linecache.getline("C:\\Users\\admin\\Desktop\\470_3_1410_1880.txt", i)
str = linecache.getline("C:\\Users\\admin\\Desktop\\5_different.txt", i)
b=str.rindex(' ')
num=float(str[b:])
list.append(num)
i=i+8
print(len(list))
Requestmeanlist=list[200:280:1]
meanValue=np.mean(Requestmeanlist)
print(meanValue)
因为要处理的txt文件是有规律的,所以代码还是很好写的