等到改变 [英] wait until change

查看:55
本文介绍了等到改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有以下问题。我分析文件中的数据。当我完成

分析该文件中的所有数据时,我想让我的程序

等到这个特定文件发生变化(这表明新数据

已经从第三方程序添加到文件中,我不会控制你的b $ b。如果该文件已更改,我希望我的程序继续。


检查文件是否更改的适当命令是什么?并且

如何实施等到进入我的计划?我google了很多,以获得任何提示,但是找不到任何有用的东西。但是我发现了一些关于2000年在纽约刺伤的蟒蛇的事情。:-)想想

这很有趣。 :-)


我非常感谢,如果你可以包含一些小的代码片段来向我展示如何使用你的建议。我是一个相对较新的python而且我经常遇到Pythons Library的问题

参考,因为它没有显示例子而且非常技术性。

这让我很难真正理解这一点。如果你能告诉我必须包含哪些模块,它也会很棒。我希望

所有这些都没有被问到太多。我假设这两个问题都可以通过几行简单的代码来解决。我只是不知道他们。 :-)


非常感谢您的帮助和建议。

问候汤姆

Hi,

I have the following problem. I analyse data from a file. When I am done
analysing all the data that was in that file, I want to let my program
wait until this specific file has changed (which indicates that new data
has been added to the file from a third party program that I don''t
control). If that file has changed, I want my program to continue.

What would be the appropriate command to check if the file changed? And
how can I implement "wait until" into my program? I googled a lot to
find any hints, but couldn''t find anything helpful. But I found
something about a python that was stabbed in NY in 2000. :-) Thought
that was funny. :-)

I would deeply appreciate, if you could maybe include some little
fragments of code to show me how to use your suggestions. I am
relatively new to python and I often have problems with Pythons Library
Reference, because it doesn''t show examples and is very technically.
That makes it difficult for me to really understand that. It also would
be great, if you could tell me which modules I have to include. I hope
all that is not asked too much. I assume that both problems can be
solved with a few easy lines of code. I just don''t know them. :-)

Thanks a lot for your help and suggestions.
Regards Tom

推荐答案

Tom写道:

我有以下问题。我分析文件中的数据。当我完成
分析该文件中的所有数据时,我想让我的程序等到这个特定文件发生变化(这表明新数据已添加到该文件中)来自我不控制的第三方程序的文件。如果该文件已更改,我希望我的程序继续。

I have the following problem. I analyse data from a file. When I am done
analysing all the data that was in that file, I want to let my program
wait until this specific file has changed (which indicates that new data
has been added to the file from a third party program that I don''t
control). If that file has changed, I want my program to continue.




是否足以让您的程序定期唤醒并且

check文件上的时间戳?要做到这一点,time.sleep()

和os.stat()的组合就足够了,而且非常跨平台。


-Peter



Would it be sufficient to have your program periodically wake up and
check the timestamp on the file? To do that, a combination of time.sleep()
and os.stat() would be sufficient, and quite cross-platform.

-Peter


2003年10月17日星期五下午12:35,汤姆写道:
On Friday 17 October 2003 12:35 pm, Tom wrote:


我有以下内容问题。我分析文件中的数据。当我完成
分析该文件中的所有数据时,我想让我的程序等到这个特定文件发生变化(这表明新数据已添加到该文件中)来自我不控制的第三方程序的文件。如果该文件已更改,我希望我的程序继续。

检查文件是否更改的适当命令是什么?并且我怎样才能实现等到进入我的计划?我google了很多,以找到任何提示,但找不到任何有用的东西。但是我发现了一些关于2000年在纽约刺伤的蟒蛇的事情。:-)思想
这很有趣。 :-)


我会使用os.stat()返回有关该文件的各种信息,包括

修改时间。


更多信息: http:// web。 pydoc.org/1.5.2/os.html


time = os.stat(file)[8]


#cnalysis data


而1:

if os.stat(file)[8]> time:

#analyze数据再次

我非常感谢,如果你可以包含一些小的代码片段来告诉我如何使用你的建议。我对python相对较新,而且我常常遇到Pythons Library
Reference的问题,因为它没有显示示例,而且技术性很强。
这让我很难真正理解那。如果你能告诉我我必须包含哪些模块,它也会很棒。我希望所有这些都不要求太多。我假设可以通过一些简单的代码来解决这两个问题。我只是不知道他们。 :-)

非常感谢你的帮助和建议。
关心汤姆
Hi,

I have the following problem. I analyse data from a file. When I am done
analysing all the data that was in that file, I want to let my program
wait until this specific file has changed (which indicates that new data
has been added to the file from a third party program that I don''t
control). If that file has changed, I want my program to continue.

What would be the appropriate command to check if the file changed? And
how can I implement "wait until" into my program? I googled a lot to
find any hints, but couldn''t find anything helpful. But I found
something about a python that was stabbed in NY in 2000. :-) Thought
that was funny. :-)
I would use os.stat() which returns all sorts of info about the file including
modification time.

More info at: http://web.pydoc.org/1.5.2/os.html

time=os.stat(file)[8]

# analyze data

while 1:
if os.stat(file)[8]>time:
#analyze data again

I would deeply appreciate, if you could maybe include some little
fragments of code to show me how to use your suggestions. I am
relatively new to python and I often have problems with Pythons Library
Reference, because it doesn''t show examples and is very technically.
That makes it difficult for me to really understand that. It also would
be great, if you could tell me which modules I have to include. I hope
all that is not asked too much. I assume that both problems can be
solved with a few easy lines of code. I just don''t know them. :-)

Thanks a lot for your help and suggestions.
Regards Tom



我肯定有很多方法可以这样做。


祝你好运,

LGL


I''m sure there are a number of ways to do this.

Good Luck,
LGL


Lane LiaBraaten写道:
Lane LiaBraaten wrote:
我会使用os.stat()返回有关该文件的各种信息,包括修改时间。

更多信息: http://web.pydoc.org/1.5.2/os.html

时间= os.stat(文件)[8]

#分析数据

1:
如果是os.stat(文件)[8]>时间:
#analyze data
I would use os.stat() which returns all sorts of info about the file including
modification time.

More info at: http://web.pydoc.org/1.5.2/os.html

time=os.stat(file)[8]

# analyze data

while 1:
if os.stat(file)[8]>time:
#analyze data again



Hi Lane,


谢谢你你的答案很有效,并且给了我很多新的想法

我可以使用。

那个1和1命令看起来很有意思。我从来没用过那种方式。

图书馆参考书并没有解释。但是,如果我假设

这是一个永远持续的循环,我是对的吗?尽管使用了

课程。我问,因为你的建议有效,但遗憾的是使用了我的CPU功率100%的b $ b。 :-(嗯,它有效,但有没有另外一种方式

可以在不使用我的资源的情况下做同样的事情?:-)那将是很好的b / b



再次感谢'。

Tom


Hi Lane,

thanks for your answer it works great and gives me a lot of new ideas
that I can work with.
That "while 1" command looks interessting. I never used while that way.
The Library Reference doesn''t explain it. But am I right if I assume
that this is a loop that continues forever? Despite using break of
course. I ask, because your suggestion works, but unfortunately uses
100% of my CPU power. :-( Well, it works, but is there maybe another way
to do the same without using so much of my resources? :-) That would be
great.

Thank''s again.
Tom


这篇关于等到改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆