[Python-ideas] Revised**12 PEP on Yield-From

Erik Groeneveld erik at cq2.org
Fri Apr 24 09:27:35 CEST 2009


Hi Nick,

2009/4/23 Nick Coghlan <ncoghlan at gmail.com>:
> So what's wrong with doing something like the following?:
>
>  def dummy_example():
>    pushback = None
>    while 1:
>      item, pushback = yield from read_item(pushback)
>      process_item(item)
>
>  def read_item(init_data=None):
>    if init_data is not None:
>      # Initialise state based on init_data
>    else:
>     # Use default initial state
>    # Read enough data to get a complete item
>    # Since this is a coroutine, there will be at least 1 yield
>    return item, excess_data

Well, there is nothing wrong with this code, but I don't want to
repeat it for every generator and every generator 'call', just because
one of them *might* have excess data.  I would like a generic solution
to have this code only once, but I can't see a solution yet.

Erik



More information about the Python-ideas mailing list