On Mon, 02 May 2005 07:46:31 -0600, Shane Hathaway <[EMAIL PROTECTED]> wrote:
>Anders J. Munch wrote:
>>     in opening('file1') as f1:
>>         ...
>>         in opening('file2') as f2:
>>             ...
>>     except IOError:
>>         print "file1 not available, I'll try again later"
>>
>> I rather like this version, because it is patently clear what should
>> happen if there is no except-clause: The exception propagates
>> normally.
>
>My eyes would expect the exception handler to also catch IOErrors
>generated inside the block statement body.  My eyes would be deceiving
>me, of course, but Python isn't currently so subtle and it probably
>shouldn't be.
>
>You could also do this with a suitable iterator.
>
>    def opening_or_skipping(fn):
>        try:
>            f = open(fn)
>        except IOError:
>            print "file1 not available, I'll try again later"
>        else:
>            try:
>                yield f
>            finally:
>                f.close()

  I don't think this version is really of much use.  It requires that you 
implement a different iterator for each kind of error handling you want to do.  
Avoiding multiple different implementations is supposed to be one of the main 
selling points of this feature.

  Jp
_______________________________________________
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