Nick Coghlan wrote:
> Steven Bethard wrote:
> 
>>If I've misunderstood, and there are other situations when
>>"needs_finish" is required, it'd be nice to see some more examples.
> 
> 
> The problem is try/except/else blocks - those are currently legal, so the 
> programmer has to make the call about whether finalisation is needed or not.
> 
> I'll put this in the Open Issues section of the PEP - doing it lexically 
> seems a 
> little too magical for my taste (since it suddenly becomes more difficult to 
> do 
> partial iteration on the generator), but the decorator is a definite wart.

I had a better idea - with a decorator being used to create statement templates 
out of generators, that means the __enter__() and __exit__() methods of 
generators themselves are available to handle finalisation.

So, just as my PEP suggests that files be usable like:

   with open(filename) as f:
       for line in f:
           print line

It now suggests generators be usable like:

   with all_lines(filenames) as lines:
       for line in lines:
           print line

Cheers,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to