【发布时间】:2014-06-19 06:30:22
【问题描述】:
我的 python 脚本中有这行代码。它在特定目录中的所有文件中搜索 *cycle *.log。
for searchedfile in glob.glob("*cycle*.log"):
这非常有效,但是当我将脚本运行到网络位置时,它不会按顺序搜索它们,而是随机搜索。
有没有办法强制代码按日期顺序搜索?
这个问题已经被问到 php 但我不确定它们的区别。
谢谢
【问题讨论】:
-
最终代码:
searchedfiles = glob.glob("*cycle*.log")searchedfiles.sort(key=os.path.getmtime)for searchedfile in searchedfiles: