[Python-Dev] PEP 343 rewrite complete
Nick Coghlan
ncoghlan at gmail.com
Thu Jun 2 17:08:27 CEST 2005
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 | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
More information about the Python-Dev
mailing list