getting errno from OSError exception?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Harrison

    #1

    getting errno from OSError exception?

    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


    Many TIA!
    Mark

    --
    Mark Harrison
    Pixar Animation Studios
  • George Yoshida

    #2
    Re: getting errno from OSError exception?

    Mark Harrison wrote:

    [color=blue]
    > 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
    >[/color]

    What about this?

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


    - george

    Comment

    Working...