How to make an empty generator?

Ben Finney ben+python at benfinney.id.au
Fri Feb 19 08:01:52 CET 2010


Robert Kern <robert.kern at gmail.com> writes:

> On 2010-02-18 18:33 PM, Ben Finney wrote:
> > Robert Kern<robert.kern at gmail.com>  writes:
> >
> >> He doesn't want *any* empty generator. He wants an iterator that
> >> executes some given side-effect-producing code then immediately
> >> raises the StopIteration.
> >
> > Ah, hm. That's a rather perverse use case, but I'm sure the OP has their
> > reasons.
>
> Which he explained fairly clearly, I thought, in his original post.

(The original post isn't available to me; the reference in your reply
isn't accessible AFAICT.)

In the part of the original that you quoted, he speaks only of empty
generators (easy and clean), not generators that exist only for the
purpose of side-effects without yielding any items.

It's that latter that I describe as perverse, and I would think it worth
some effort to determine if that can be avoided by a different approach.

-- 
 \        “The problem with television is that the people must sit and |
  `\    keep their eyes glued on a screen: the average American family |
_o__)                 hasn't time for it.” —_The New York Times_, 1939 |
Ben Finney



More information about the Python-list mailing list