On May 19, 8:42 am, Alan Franzoni <[email protected]>
wrote:
> Hello,
> I was looking for an ABC for generators in python. While there's a
> types.GeneratorType type object - which can't be used directly and it's
> not an abc - and many collections-related ABCs in the collections
> module, there's no way to say a user-defined class as a generator, even
> though it could expose the very same interface as a builtin, yield-based
> generator.
>
> I think it would be pretty useful.
>
> comments?
collections.Iterator
You don't actually need abc's to write custom iterators, BTW, the
following is an iterator for instance.
class Noise:
def __iter__(self):
return self
def __next__(self):
return random.random()
which is equivalent to the generator
def Noise():
while True:
yield random.random()
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list