【发布时间】:2014-02-13 06:23:35
【问题描述】:
我需要等到文件创建后再读入。我有以下代码,但确定它不起作用:
import os.path
if os.path.isfile(file_path):
read file in
else:
wait
有什么想法吗?
【问题讨论】:
-
循环几秒钟
time.sleep? -
while not os.path.isfile(): sleep(.1)? -
不要用
isfile去检查文件是否存在,用exists再做stat -
你可以重复检查一个循环,但如果你想要更智能的东西,你可以使用 inotify:pypi.python.org/pypi/inotify/0.2.9
标签: python