wrapping yield ?

Michael Sparks Michael.Sparks at rd.bbc.co.uk
Fri Sep 13 12:17:40 CEST 2002

"Duncan Booth" <duncan at NOSPAMrcp.co.uk> wrote in message
news:Xns92885F082A21Cduncanrcpcouk at
> So something like this should work:
> def my_generator(arg):
>    dostuff....
>    for item in waitForSomethingCheckingPeriodically():
>       if item is None:
>           yield None
>       else:
>           processit(item)

Whereas if I could wrap up yield, I simply have to do:

item = waitForSomethingCheckingPeriodically()

Which if I have lots of this sort of thing going on, results in much
clearer (and hence maintainable) code.

If it can't (putting yield in a function, and not turning the function into
generator) be done, and AFAICT it can't, and this is a suggested work
around - many thanks :-)

Best Regards,


More information about the Python-list mailing list