for i in <instance>

Lyle Johnson ljohnson at resgen.com
Wed Jun 20 14:55:05 EDT 2001


> what was overloaded in UserList so its items could be extracted when you
do
>
> for i in UserList([1,2,3])
> ?

To emulate sequence types (like lists and tuples) you can overload the
__len__() and __getitem__() magic methods. See "Emulating sequence and
mapping types", section 3.3.4 of the Python Language Reference Manual, for
more details.





More information about the Python-list mailing list