posix.error is a tuple, not an object or a string as docs say
Ben Gertzfield
che at debian.org
Tue Aug 10 13:09:14 EDT 1999
Today I was trying to use the posix.fdopen() function (through
os.fdopen() as recommended in the documentation) so that I could open
a pre-existing file descriptor passed in through sys.argv to a normal
Python file object.
Obviously I want to be able to catch errors in case the file
descriptor passed through sys.argv isn't legal, so I read the nice
documentation for posix.error:
error
This exception is raised when a POSIX function returns a
POSIX-related error (e.g., not for illegal argument types). The
accompanying value is a pair containing the numeric error code
from errno and the corresponding string, as would be printed by
the C function perror(). See the module errno , which contains
names for the error codes defined by the underlying operating
system.
When exceptions are classes, this exception carries two
attributes, errno and strerror. The first holds the value of
the C errno variable, and the latter holds the corresponding
error message from strerror().
When exceptions are strings, the string for the exception is
'os.error'; this reflects the more portable access to the
exception through the os module.
This doesn't seem to be quite true, however:
Python 1.5.1 (#1, Dec 17 1998, 20:58:15) [GCC 2.7.2.3] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import os
>>> try:
... input = os.fdopen(42)
... except os.error, error:
... print error
...
(9, 'Bad file descriptor')
'error', in this case, is a tuple, not an object. Am I incorrect in
thinking this? If so, how do I access the aforementioned attributes
errno and strerror?
Obviously it's no problem to just say:
except os.error, error:
errnum, errstr = error
but this contradicts the documentation for posix.error -- and there is
no documentation for a separate os.error, so I assume they are one and
the same.
I guess I'm missing something major, but it's odd that the docs don't
match reality at all.
Ben
--
Brought to you by the letters Z and S and the number 10.
"More testicles means more iron."
Debian GNU/Linux maintainer of Gimp and GTK+ -- http://www.debian.org/
More information about the Python-list
mailing list