print(7)
sleep(10)
print(8)
當我在Spyder的命令行中輸入了這個信息時,我期望7被打印,然後在10秒後打印8,但是,發生的事情是7和8都是爲什麼會出現這種情況呢?time.sleep in python exceution order
我需要這個功能的原因是我希望Python繼續搜索目錄中的文件,直到它最終出現。
done = os.path.exists ("done.txt")
while not done:
sleep(10)
done = os.path.exists ("done.txt")
這項工作?
編輯:糾正存在爲存在。
可能重複的[Python3睡眠()問題](http://stackoverflow.com/questions/4456581/python3-sleep-problem) – Blorgbeard
對於你的問題不會'一次'初始化一次?那麼「睡眠(10)」將不會發生。也許你應該檢查'os.path.exist()'作爲'while'條件。像'while os.path.exists('/ your/path/file.txt')'? –
它應該是'os.path.exists'而不是'os.path.exist'。除此之外,這應該工作得很好。 –