Can This Code Be Made Faster?

Michael Peuser mpeuser at web.de
Fri Sep 12 07:07:10 EDT 2003


"John Abel" <john.abel at pa.press.net> schrieb im Newsbeitrag
news:mailman.1063358599.4816.python-list at python.org...
> 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?


I think best help is with try - except (Ganesan already posted...)
But by all means NEVER use except: without any explicit exception; in this
case
     except OSError:
would be appropriate.

If you by chance are using Windows only, a much better (and much faster)
suport will be given by
      win32api.FindFiles
Of course this is not portable....

Kindly
Michael P






More information about the Python-list mailing list