Exceptions, assigning a tuple

Derek Fountain nomail at hursley.ibm.com
Fri Nov 21 02:18:49 EST 2003


>> except IOError, (errno, strerror):
> This is just using tuple unpacking in assignment:
> 
>>>> tup = 1, 2, 3
>>>> x, y, z = tup
>>>> x
> 1
>>>> y
> 2
>>>> z
> 3

OK, that makes a lot of sense. However, the thing being unpacked here isn't
a tuple - it's an object of type IOError. How does an object know how to
unpack itself when used in an assignment like this? More specifically, how
does the IOError object know to return its errno and strerror values when
it gets assigned to a 2 value tuple?




More information about the Python-list mailing list