[Python-Dev] yeah! for Jeremy and Greg

Ka-Ping Yee ping@lfw.org
Tue, 28 Mar 2000 19:17:27 -0600 (CST)


On Tue, 28 Mar 2000, Barry A. Warsaw wrote:
> 
> Changing the definition of class Nums to
> 
> class Nums:
>     def __getitem__(self, i):
>         if 0 <= i < 10: return i
>         raise IndexError
>     def __len__(self):
>         return 10
> 
> I.e. adding the __len__() method avoids the SystemError.

It should be noted that "apply" has the same problem, with a
different counterintuitive error message:

    >>> n = Nums()
    >>> apply(sum, n)
    Traceback (innermost last):
      File "<stdin>", line 1, in ?
    AttributeError: __len__


-- ?!ng