Guido van Rossum wrote:
> I hope that I've got the rewrite of PEP 343 to include generator
> extensions right now. I've chosen the 'with' keyword. Please review
> here; I think this is ready for review by the unwashed masses. :-)
>
> http://www.python.org/peps/pep-0343.html
>
Looks pretty good to me (looking at version 1.19).
One comment is that, in the 'optional extensions' section, where you
say 'such mistakes are easily diagnosed', you could point to your
generator wrapper as an example where attempting to reuse the block
handler raises a RuntimeError on the second attempt.
Also, I'm wondering if it would be useful to have a 'closing' template
that looked like:
@with_template
def closing(obj):
try:
yield obj
finally:
obj.close()
That can be used to deterministically close anything with a close
method, be it file, generator, or something else:
with closing(open("argument.txt")) as contradiction:
for line in contradiction:
print line
with closing(some_gen()) as data:
for datum in data:
process(datum)
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com