Can This Code Be Made Faster?

John Abel john.abel at pa.press.net
Fri Sep 12 05:19:28 EDT 2003


I have a problem, in that the following code is sometimes failing.  I am 
stat'ing a list of files, but, sometimes, one of the files may be moved 
by an external process, after the os.path.exists and before the lstat, 
causing the script to fail.  My question, is there anything I can do to 
speed it up, or put in a trap, to stop the stat from failing?

        fileTimes = [ ( os.lstat( os.path.join( rootPath, fileName ) 
)[stat.ST_MTIME], fileName) for fileName in fileList \
                                                                            
if os.path.exists( os.path.join( rootPath, fileName ) ) ]

I'd appreciate any pointers.

John









More information about the Python-list mailing list