wrapping yield ?

Michael Sparks Michael.Sparks at rd.bbc.co.uk
Fri Sep 13 06:17:40 EDT 2002


"Duncan Booth" <duncan at NOSPAMrcp.co.uk> wrote in message
news:Xns92885F082A21Cduncanrcpcouk at 127.0.0.1...
...
> 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()
process(item)

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
a
generator) be done, and AFAICT it can't, and this is a suggested work
around - many thanks :-)

Best Regards,


Michael.






More information about the Python-list mailing list