How to make an empty generator?

Arnaud Delobelle arnodel at googlemail.com
Fri Feb 19 03:36:28 EST 2010


Ben Finney <ben+python at benfinney.id.au> writes:

> Arnaud Delobelle <arnodel at googlemail.com> 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).

-- 
Arnaud



More information about the Python-list mailing list