我正在编写脚本来检查文件并打印出zip文件及其创建日期。我的程序对少于5MB的数据有效,但如果我在超过15MB的数据上运行它,生成输出需要几个小时。以下是我的代码示例。我怎样才能优化我的代码,使其运行速度更快?需要很长时间才能运行的python脚本
import os, argparse
from datetime import datetime
#Returns a list of directories of all zip files.
def findZip_Dir_list(cwd):
userList = []
for (dirname, dirs, files) in os.walk(cwd):
for filename in files:
if filename.endswith('.zip'):
fileDir = os.path.join(dirname, filename)
t = os.path.getmtime(fileDir)
userList.append(os.path.join(fileDir, str(t)))
return userList
cwd = os.getcwd()
testList = findZip_Dir_list(cwd)
print(tesList)
也许https://pypi.python.org/pypi/glob2? – Kevin