Python-如果没有新条目,则循环结束
在这篇文章之后: 我被告知这段代码已经在一次读取一大块行了:Python-如果没有新条目,则循环结束,python,Python,在这篇文章之后: 我被告知这段代码已经在一次读取一大块行了: file = open('logFile.txt', 'r') count = 0 while 1: where = file.tell() for line in file: if not line: count = count + 1 if count >= 10: break time
file = open('logFile.txt', 'r')
count = 0
while 1:
where = file.tell()
for line in file:
if not line:
count = count + 1
if count >= 10:
break
time.sleep(1)
file.seek(where)
else:
try:
#process line
如果是这样,那么脚本如何检查一段时间内是否没有新行,结束for循环并继续脚本?我数数了一段时间,但那不起作用你应该看看这个问题的答案。我认为你不需要这么做,正如你提到的那篇文章,open已经可以帮助您找出将if-not行的主体:语句移出file循环中的for行的错误吗?@PaulLo the循环一直在等待新行。如果没有新台词,我想结束它minutes@Learner:文件中的for行循环将在没有更多行时停止。