On Mon, Dec 14, 2015 at 4:48 PM, Vincent Davis <vinc...@vincentdavis.net> wrote:
> On Mon, Dec 14, 2015 at 4:14 PM, Cameron Simpson <c...@zip.com.au> wrote:
>
>> First, notice that the code inside the try/except _only_ fetches the
>> attribute.  Your version calls the "write" attribute, and also accesses
>> handle.name. Either of those might also emit AttributeError, and should
>> probably not be silently caught.
>>
>
> I think the intent of the original code was to check if handle had the
> attribute "name", I don't think the attribute "write" was the issue.
>
> So then possibly this based on your suggestion:
> try:
>     write = handel.write
> except AttributeError:
>     raise

Except that catching an exception just to immediately re-raise it is
silly. This would be better:

try:
    name = handle.name
except AttributeError:
    pass
else:
    handle.write("# Report_file: %s\n" % name)
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to