getting errno from OSError exception?

George Yoshida ml at
Mon Sep 13 20:01:09 CEST 2004

Mark Harrison wrote:

> Can somebody loan me a clue as to how to check the errno on
> an OSError, as described below?
> try:
>     os.makedirs(d)
> except OSError:
>     # if errno == 17 then silently ignore the error because the
>     # other process won the race condition and created the directory
>     # otherwise, allow the exception to percolate up the call stack
>     # and be caught by the standard error reporter

What about this?

except OSError, e:
   if e.errno == 17:

- george

More information about the Python-list mailing list