getting errno from OSError exception?

George Yoshida ml at dynkin.com
Mon Sep 13 14:01:09 EDT 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?

try:
   os.makedirs(d)
except OSError, e:
   if e.errno == 17:
     do_something


- george



More information about the Python-list mailing list