How to make an empty generator?

Arnaud Delobelle arnodel at
Fri Feb 19 09:36:28 CET 2010

Ben Finney <ben+python at> writes:

> Arnaud Delobelle <arnodel at> writes:
>> What about
>>     foo = iter('')
> That doesn't return a generator.
>     >>> foo = iter('')
>     >>> foo
>     <listiterator object at 0xf7cd3ed0>
> Whether the OP needs to create a generator, or just any iterable type,
> isn't clear.

If it walks and quacks like a duck... Anyway it's not just an iterable
object, it's an iterator.  I can't really imagine that there would be
some code which would be happy with generators but not with iterators
(as long as you can't send anything to them, which is always the case
with an empty generator).


More information about the Python-list mailing list