Re: Supporting list()

2012-12-17 Thread Dave Angel
On 12/17/2012 06:27 PM, Ethan Furman wrote: > Dave Angel wrote: >> On 12/17/2012 09:33 AM, Skip Montanaro wrote: >>> What method(s) does a class have to support to properly emulate a >>> container >>> which supports turning it into a list? For example: >>> >>> class Foo: >>> pass >>> >>> f

Re: Supporting list()

2012-12-17 Thread Ethan Furman
Dave Angel wrote: On 12/17/2012 09:33 AM, Skip Montanaro wrote: What method(s) does a class have to support to properly emulate a container which supports turning it into a list? For example: class Foo: pass f = Foo() print list(f) Is it just __iter__() and next()? (I'm still usin

Re: Supporting list()

2012-12-17 Thread Skip Montanaro
> If using __getitem__ it needs to work with integers from 0 to len(f)-1, > and raise IndexError for len(f), len(f+1), etc. Ah, thanks. I have a __getitem__ method, but it currently doesn't raise IndexError. (I'm indexing into a ring buffer, and the usage of the class pretty much precludes index

Re: Supporting list()

2012-12-17 Thread Ethan Furman
Skip Montanaro wrote: What method(s) does a class have to support to properly emulate a container which supports turning it into a list? For example: class Foo: pass f = Foo() print list(f) Is it just __iter__() and next()? (I'm still using 2.4 and 2.7.) You can either use __ite

Re: Supporting list()

2012-12-17 Thread Dave Angel
On 12/17/2012 09:33 AM, Skip Montanaro wrote: > What method(s) does a class have to support to properly emulate a container > which supports turning it into a list? For example: > > class Foo: > pass > > f = Foo() > print list(f) > > Is it just __iter__() and next()? (I'm still using 2.

Supporting list()

2012-12-17 Thread Skip Montanaro
What method(s) does a class have to support to properly emulate a container which supports turning it into a list? For example: class Foo: pass f = Foo() print list(f) Is it just __iter__() and next()? (I'm still using 2.4 and 2.7.) Thx, Skip -- http://mail.python.org/mailman/l