【发布时间】:2021-08-08 14:35:03
【问题描述】:
可以用这段代码写下一行吗? 怎么做? 我想读(n)行,然后做数学写(n+1),无限循环。
import time
def follow(thefile):
thefile.seek(0,2)
while True:
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
if __name__ == '__main__':
logfile = open("myfile.txt","r+")
loglines = follow(logfile)
for line in loglines:
write.logfile ("5*2+1\n")
【问题讨论】:
-
@MauriceMeyer 但它只工作 1 次,我需要循环不停读第 n 行,然后写 n + 1。
-
请分享你的代码,否则没人知道你在说什么
-
@MauriceMeyer 这是我的新问题,谢谢stackoverflow.com/questions/68702899/…
标签: python