overloading *something

James Stroud jstroud at mbi.ucla.edu
Tue Nov 8 06:03:24 CET 2005


On Monday 07 November 2005 20:36, Alex Martelli wrote:
> > > I've looked at getitem, getslice, and iter. What is it if not one of
> > > these?
>
> Obviously James hadn't looked at __iter__ in the RIGHT way!

I was attempting to re-define iter of a subclassed list, to find the "magic" 
method, but it didn't work. I'm not sure if "wrong" and "right" apply here:

py> class NewList(list):
...   def __iter__(self):
...     return iter([8,9,10])
...
py>
py> n = NewList([1,2,3])
py>
py> def doit(*args):
...   print args
...
py> doit(*n)
(1, 2, 3)
py> for x in iter(n):
...   print x
...
8
9
10


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list