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
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
> 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
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
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.
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