[Python-ideas] iterable: next() and __iter__() -- and __reset()
masklinn at masklinn.net
Thu Mar 4 13:41:14 CET 2010
On 4 Mar 2010, at 12:53 , spir wrote:
> Right, but this pattern only replaces cubes(6, 16) by islice(cubes, 6, 16)
Yes, the point is that you don't *need* cubes to be callable to do what you want. Because Python already provides the tools to do it in its stdlib. So you have no reason to concern yourself with that.
> Does the following match your idea?
> def __getitem__(self, ranj):
> self.n , self.max = ranj.start-1 , ranj.stop-1
> return self
I'd return a new item with the relevant attributes set, not an modified set (generally, I'm not fond of mutable object but that might just be me)
More information about the Python-ideas