How to make an empty generator?
robert.kern at gmail.com
Fri Feb 19 16:51:54 CET 2010
On 2010-02-19 00:21 AM, Steven D'Aprano wrote:
> On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote:
>>>> What's the point of the wheel spinning? Did I miss something?
>>> I wonder whether it's for some kind of framework with a main loop like
>>> for it in list_of_iterables:
>>> for x in it:
>>> do_this_or_that (x)
>>> where, every once in a while one wants to throw some arbitrary code
>>> into the process, in the form of an empty iterable with side effects.
>> Yes. That is exactly what the OP said in his original post:
>> I have some generators that do stuff, then start yielding results. On
>> occasion, I don't want them to yield anything ever-- they're only really
>> "generators" because I want to call them /as/ a generator as part of a
>> generalized system. """
> But he doesn't say anything about side-effects.
"I have some generators *that do stuff*, then start yielding results." [emphasis
mine]. Then he gives an example of a generator that does side-effect stuff and
returning before yielding anything.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list