我想檢查連續更新文本文件的特定列的長度。文本文件格式如下:在Python中檢查更新文本文件的一列
1,-18,02,-18,02,-18,02,-18,02,-18,02,-18,02,-18,02,-18 ,02,0,00,0,00,0,00
2,-18,02,-18,02,-18,02,-18,02,-18,02,-18,02, -18,02,-18,02,0,00,0,00,0,00
3,-18,02,-18,02,-18,02,-18,02,-18, 02,-18,02,-18,02,-18,02,0,00,0,00,0,00
因此在1分鐘內在文本文件中自動寫入15000行。在Python代碼中,我想檢查這個文本文件的第一列的長度,當它達到15000的長度時,我想退出循環。下面是我的代碼相關部分:
def myfun(inputpath, outpath):
fs = 250 #sampling frequency
n = 1
mincounter = 1
loc = []
result = []
while n < 30000:
while (len(loc) < (mincounter*15000)+1):
f=open(inputpath,"r")
lines=f.readlines()
result=[]
for x in lines:
loc.append(x.split(',')[0])
for x in lines:
result.append(x.split(',')[1])
print (len(loc))
print ("a")
f.close()
vms = [float(x) for x in result]
print("15000 Lines Had Written")]
然而,「LOC」陣列的長度幾乎5秒而超過1分鐘達到15000雖然文本文件具有不15000線太。並且在5秒內得到「15000行已寫入」的輸出。那麼,如何在連續更新文本文件中正確檢查這個長度?
感謝
你能修復函數的縮進嗎? – tdelaney
列0是行數嗎?你能在那一欄找15000嗎? – tdelaney
嗨,縮進是正確的。沒有Ithink我不能在那個專欄中尋找15000,因爲當它達到250時,它會回到0,因此在60圈時它在1分鐘內達到15000。 –