Yield inside try...finally

Steven Taschuk staschuk at telusplanet.net
Tue Jun 3 13:48:08 EDT 2003


Quoth Michael Sparks:
> I've been working with wrapping up network client functionality as a
> generator recently, and hit a "niceness"/"cleanness" speedbump.
  [...]
> Given these 3 versions, the one not allowed (the try..finally) one
> strikes me as the cleanest.
> 
> I'm posting this really for a couple of reasons - a) to note that
> try..yield..finally would occasionally be a really useful thing
> to have (*) [...]

What if the caller of your code calls .next for a while, then
discards the iterator and does something else?  Then the finally
block will not be executed.

-- 
Steven Taschuk                               staschuk at telusplanet.net
"[T]rue greatness is when your name is like ampere, watt, and fourier
 -- when it's spelled with a lower case letter."      -- R.W. Hamming





More information about the Python-list mailing list