detecting and creating directories

Steve Holden sholden at holdenweb.com
Mon Oct 29 16:55:48 EST 2001


"Fredrik Lundh" <fredrik at pythonware.com> 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
--
http://www.holdenweb.com/






More information about the Python-list mailing list