How to make an empty generator?
steve at REMOVE-THIS-cybersource.com.au
Fri Feb 19 07:21:48 CET 2010
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. If you're passing
generators around, sometimes you want an empty generator, just as
sometimes you want an empty string, or list, or whatever.
More information about the Python-list