Why is there no instancemethod builtin?

George Sakkis gsakkis at rutgers.edu
Sun Jun 19 22:17:50 CEST 2005

"John Roth" wrote:

> Unfortunately it doesn't work: getitem can be defined for
> a class that acts like a dictionary: that is, the items are
> not integers, let alone integers that extend in a strict
> sequence from 0.

This is true, but that's the current behaviour of iterators for classes
that define __getitem__ without __iter__:

class AnIterable(object):
    def __init__(self, it): self._it = it
    def __getitem__(self,i): return self._it[i]

>>> x = AnIterable(dict(a=1,b=2))
>>> list(x)

KeyError: 0


More information about the Python-list mailing list