>>> a == 1 and b == 2 and c == 3
>>> a == 4 and b == 5 and c == 6
>>> a == 7 and b == 8 and c == 9
>>> a == 'o' and b == 'n' and c == 'e'
... def __getitem__(self, i):
... if i >= 0 and i < 3: return i
>>> a == 0 and b == 1 and c == 2
Single element unpacking, with extra syntax
Traceback (most recent call last):
TypeError: unpack non-sequence
Unpacking tuple of wrong size
Traceback (most recent call last):
ValueError: too many values to unpack
Unpacking tuple of wrong size
Traceback (most recent call last):
ValueError: too many values to unpack
Unpacking sequence too short
Traceback (most recent call last):
ValueError: need more than 3 values to unpack
Unpacking sequence too long
Traceback (most recent call last):
ValueError: too many values to unpack
Unpacking a sequence where the test for too long raises a different kind of
>>> class BozoError(Exception):
... def __getitem__(self, i):
Trigger code while not expecting an IndexError (unpack sequence too long, wrong
>>> a, b, c, d, e = BadSeq()
Traceback (most recent call last):
Trigger code while expecting an IndexError (unpack sequence too short, wrong
Traceback (most recent call last):
__test__
= {'doctests' : doctests
}
def test_main(verbose
=False):
from test
import test_support
from test
import test_unpack
test_support
.run_doctest(test_unpack
, verbose
)
if __name__
== "__main__":