<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Greg Ewing wrote:<br>
<blockquote cite="mid:49950F80.5050309@canterbury.ac.nz" type="cite">
_i = iter(expr)
<br>
try:
<br>
_u = _i.next()
<br>
_v = yield
<br>
while 1:
<br>
try:
<br>
_v = yield _u
<br>
except Exception, _e:
<br>
if hasattr(_i, 'throw'):
<br>
_i.throw(_e)
<br>
else:
<br>
raise
<br>
else:
<br>
if hasattr(_i, 'send'):
<br>
_u = _i.send(_v)
<br>
else:
<br>
_u = _i.next()
<br>
except StopIteration, _e:
<br>
_a = _e.args
<br>
if len(_a) > 0:
<br>
result = _a[0]
<br>
else:
<br>
result = None
<br>
finally:
<br>
if hasattr(_i, 'close'):
<br>
_i.close()
<br>
<br>
</blockquote>
A couple of points here:<br>
<ol>
<li>I don't believe that you want the first yield statement (line
4). I think that this line should be deleted.</li>
<li>I would suggest returning the final value from <tt>close</tt>
rather than attached to <tt>StopIteration</tt>. Thus, the entire <tt>except
StopIteration</tt> clause may be deleted, and <tt>_i.close()</tt>
changed to <tt>result = _i.close()</tt> (and an <tt>else: result =
None</tt>).</li>
</ol>
-bruce frederiksen<br>
</body>
</html>