"Ganesan R" <rg******@myrea lbox.com> wrote in message
news:ou******** ****@andlx-anamika.cisco.c om...
>> "John" == John Abel <jo*******@pa.p ress.net> writes:
[snip] ======
fileTimes = []
for fileName in fileList:
try:
fileTimes.appen d(
(os.lstat(os.pa th.join(rootPat h, fileName)).st_m time,
fileName) )
except:
pass
======
def getFileTimes(fi leList, rootPath):
# using a function can speed things up (I seem to recall)
fileTimes = []
# use aliases to save some look-up time inside loop
append = fileTimes.appen d; lstat = os.lstat; joinPath = os.path.join;
for fileName in fileList:
try:
append((lstat(j oinPath(rootPat h, fileName)).st_m time, fileName))
except OSError:
pass
return fileTimes
I don't know if function composition would help speed (you'd have to
timeit.py),
but it might help readability:
# from "Python Cookbook", pg. 467
def compose(f, g, *orig_args, **orig_kwds):
def nested_function (*more_args, **more_kwds):
return f(g(*more_args, **more_kwds), *orig_args, **orig_kwds)
return nested_function
def getFileTimes2(f ileList, rootPath):
fileTimes = []
append = fileTimes.appen d
lstat = compose(os.lsta t, os.path.join)
for fileName in fileList:
try:
append( (lstat(rootPath , fileName).st_mt ime, fileName) )
except OSError:
pass
return fileTimes
HTH
Sean