Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100437

Re: Try: rather than if :

From Vincent Davis <vincent@vincentdavis.net>
Newsgroups comp.lang.python
Subject Re: Try: rather than if :
Date 2015-12-14 16:48 -0700
Message-ID <mailman.3.1450136961.22044.python-list@python.org> (permalink)
References <CALyJZZViT33d8iob-5PoYnJOdPU2RzSzt3YAic_GRaAxN+wE1A@mail.gmail.com> <20151214231420.GA20631@cskk.homeip.net>

Show all headers | View raw


On Mon, Dec 14, 2015 at 4:14 PM, Cameron Simpson <cs@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
try:
    name = handel.name
    write("# Report_file: %s\n" % name)
except AttributeError:
    pass
write("########################################\n")


Vincent Davis
720-301-3003

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Try: rather than if : Vincent Davis <vincent@vincentdavis.net> - 2015-12-14 16:48 -0700

csiph-web