detecting and creating directories

Steve Holden sholden at
Mon Oct 29 22:55:48 CET 2001

"Fredrik Lundh" <fredrik at> wrote ...
> Steve wrote:
> > import os
> > path = "/usr/tmp/newdir"
> > if os.path.exists(path):
> >     if not os.path.isdir(path):
> >         raise ValueError, "%s exists but is not a directory" % path
> > else:
> >     os.mkdir(path)
> for ten extra points, explain why this is a lousy way to
> do this.

Because the effbot is inherently clueful, and has suggested this is not the
best way?

It would be nice, of course, to ensure that the mkdir() had generated a
writable directory. Or that an existent directory was writable. Those cases
would be handled by the open-for-writing code that created the file, though.
I'm sure you have much more to say than just that...

asking-for-it-ly y'rs  - steve

More information about the Python-list mailing list