How to make an empty generator?

Stephen Hansen apt.shansen at gmail.com
Thu Feb 18 23:25:12 CET 2010


This has to be a stupid question, but :)

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.

The only way I can figure out how to make an empty generator is:

    def gen():
        # do my one-time processing here

        return
        yield

Is there a better way? The return/yield just makes me flinch slightly. I
tried just raising StopIteration at the end, but of course that didn't work.

TIA,
--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100218/9f4fb2af/attachment.html>


More information about the Python-list mailing list