Speed ain't bad

Anders J. Munch andersjm at inbound.dk
Tue Jan 4 17:33:23 EST 2005


"John Machin" <sjmachin at lexicon.net> wrote:
> 1. Robustness: Both versions will "crash" (in the sense of an unhandled
> 2. Efficiency: I don't see the disk I/O inefficiency in calling

3. Don't itemise perceived flaws in other people's postings. It may
give off a hostile impression.

> 1. Robustness: Both versions will "crash" (in the sense of an unhandled
> exception) in the situation where zfdir exists but is not a directory.
> The revised version just crashes later than the OP's version :-(
> Trapping EnvironmentError seems not very useful -- the result will not
> distinguish (on Windows 2000 at least) between the 'existing dir' and
> 'existing non-directory' cases.

Good point; my version has room for improvement. But at least it fixes
the race condition between isdir and makedirs.

What I like about EnvironmentError is that it it's easier to use than
figuring out which one of IOError or OSError applies (and whether that
can be relied on, cross-platform).

> 2. Efficiency: I don't see the disk I/O inefficiency in calling
> os.path.isdir() before os.makedirs() -- if the relevant part of the
> filesystem wasn't already in memory, the isdir() call would make it
> so, and makedirs() would get a free ride, yes/no?

Perhaps. Looking stuff up in operating system tables and buffers takes
time too. And then there's network latency; how much local caching do
you get for an NFS mount or SMB share?

If you really want to know, measure.

- Anders





More information about the Python-list mailing list