Can one get "for x in y" to work for non builtin classes?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Mar 3 06:41:32 EST 2008


On Mon, 03 Mar 2008 12:17:39 +0100, M.-A. Lemburg wrote:

> It's also possible to implement .__getitem__() and .__len__()
> methods and have Python create an iterator on-the-fly. That's
> how Python used to work before iterators were added to the
> language.

A suitable `__getitem__()` is enough.  The end will be signaled by an
`IndexError`.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list