open() and EOFError
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Jul 7 19:10:45 EDT 2014
On 07/07/2014 23:09, Gregory Ewing wrote:
> Marko Rauhamaa wrote:
>> with open(path) as f:
>> ...
>>
>> If the open() call is guarded against exceptions (as it usually should),
>> one must revert to the classic syntax:
>
> Hmmm, maybe we could do with a with-except statement:
>
> with open(path) as f:
> ...
> except IOError:
> # Catches exceptions in the with-expression only
> ...
>
> Although that would be a bit confusing.
>
I wrap the with inside a try/except, the other file handling parts
within another try/except and use the finer grained exceptions from PEP
3151 to write (at least to my eye) cleaner looking code. Somehow I
think we'll get agreement on the best way to do this when the cows come
home.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
More information about the Python-list
mailing list