简体   繁体   English

如何保持 Python 脚本运行以继续读取文本文件?

[英]How to keep a Python script running to keep reading a text file?

Hello I need to find a way to keep reading a text file by a Python script.您好,我需要找到一种方法来通过 Python 脚本继续读取文本文件。 This text file should be written by a another software either a Boolean value or anything (doesn't matter).这个文本文件应该由另一个软件编写,或者 Boolean 值或任何东西(没关系)。 But as soon as the python script recognizes the keyword it should do something run other codes.但是,一旦 python 脚本识别出关键字,它就应该运行其他代码。

I am not able to find a way to keep the python script running.我无法找到保持 python 脚本运行的方法。 Any suggestions would deeply appreciated.任何建议将不胜感激。 Thank you.谢谢你。

I am using a Windows OS我正在使用 Windows 操作系统

You can use while loop to get the line, when it's just added:您可以使用 while 循环来获取该行,当它刚刚添加时:

while True:
    line = current.readline()
    if line:
        yield line

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM