我是蟒蛇新手所以请温柔..
我正在使用 glob 收集与特定模式匹配的文件列表
for name in glob.glob('/home/myfiles/*_customer_records_2323_*.zip')
print '\t', name
然后输出类似于
/home/myfiles/20130110_customer_records_2323_something.zip
/home/myfiles/20130102_customer_records_2323_something.zip
/home/myfiles/20130101_customer_records_2323_something.zip
/home/myfiles/20130103_customer_records_2323_something.zip
/home/myfiles/20130104_customer_records_2323_something.zip
/home/myfiles/20130105_customer_records_2323_something.zip
/home/myfiles/20130107_customer_records_2323_something.zip
/home/myfiles/20130106_customer_records_2323_something.zip
但我希望输出仅为最新的 5 个文件(通过时间戳或操作系统报告的创建时间)
/home/myfiles/20130106_customer_records_2323_something.zip
/home/myfiles/20130107_customer_records_2323_something.zip
/home/myfiles/20130108_customer_records_2323_something.zip
/home/myfiles/20130109_customer_records_2323_something.zip
/home/myfiles/20130110_customer_records_2323_something.zip
关于如何实现这一点的想法?(是否对列表进行了排序,然后只包含最新的 5 个文件?)
UPDATE 修改以显示默认情况下不排序 glob 的输出