Having problems with Exceptions

m mblatch at orci.com
Thu Jul 6 12:03:44 EDT 2000


I'm new at Python coding and am trying to catch
errors returned by os.open with exception handling.
All errors with os.open are returned with an OSError
exception.  So, how do I split out the individual errors
with something as simple as:

try:
  file=os.open("test",os.O_RDWR | os.O_CREAT | os.O_EXCL, 0444)

except OSError:
  {want to do different things here for errno EEXIST (file exists)
     or EACCES (Permission denied), etc.}

I have looked at the tuple returned by sys.exc_info() and can
extract the *text* of the Python error message 
(i.e. "[Errno 17] File exists"), but not the numeric error number.
I certianly don't want to have to rely on parsing the text to get 
the actual error.  I'm sure there is an easy answer to this if
someone would be kind enough to help me.

Thanks,

Mike
mblatch at orci.com



More information about the Python-list mailing list