need dict to maintain order

Jason Orendorff jason at jorendorff.com
Sat Jan 19 23:06:29 EST 2002


Aahz Maruch wrote:
> Jason Orendorff <jason at jorendorff.com> wrote:
> >rihad:
> >>
> >> try:
> >>    os.mkdir(self.dirname)
> >> except OSError:
> >>    pass
> >
> >It's better to do
> >
> >  if not os.path.isdir(self.dirname):
> >      os.mkdir(self.dirname)
> >
> >and not squelch the error, if one occurs.
> 
> I don't agree that it's unambiguously better.  I've seen a lot of
> thoughtful arguments on both sides during my years on c.l.py, and my
> stock response these days is, "it depends".

In this *particular* case I think it's unambiguously better.
If the directory exists, it's foolish to try to create it again;
if it *doesn't* exist, and you try to create it, and fail
(permission denied; or device failure), then it's foolish to
proceed and start putting files in that directory.  Right?

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list