Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100437
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Vincent Davis <vincent@vincentdavis.net> |
| Newsgroups | comp.lang.python |
| Subject | Re: Try: rather than if : |
| Date | Mon, 14 Dec 2015 16:48:58 -0700 |
| Lines | 27 |
| Message-ID | <mailman.3.1450136961.22044.python-list@python.org> (permalink) |
| References | <CALyJZZViT33d8iob-5PoYnJOdPU2RzSzt3YAic_GRaAxN+wE1A@mail.gmail.com> <20151214231420.GA20631@cskk.homeip.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de ZcsC98pT2nxH3rh0/+c6MgzvD9IxXN5VfJGbwruoc8Lg== |
| Return-Path | <vincent@vincentdavis.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'skip:p 60': 0.05; '%s\\n"': 0.09; 'attribute.': 0.09; 'name)': 0.09; 'received:209.85.218': 0.10; 'accesses': 0.16; 'attribute,': 0.16; 'emit': 0.16; 'fetches': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simpson': 0.16; 'try/except': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'try:': 0.18; '2015': 0.20; 'first,': 0.20; 'issue.': 0.20; 'to:name:python-list@python.org': 0.20; 'pass': 0.22; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; '14,': 0.27; 'raise': 0.29; 'code': 0.30; 'probably': 0.31; 'possibly': 0.32; 'except': 0.34; 'handle': 0.34; 'received:google.com': 0.35; 'should': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'version': 0.38; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'your': 0.60; 'cameron': 0.66; 'intent': 0.66 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=vincentdavis.net; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=U62Q4+UdILDr8BGU/+q+roLGufJvo+p0AJuntKtMlJE=; b=XO1ZecNwCf2PP3mQL14vPLAWtRmyoE6ycOhmFz7HUsrouDtaDIblYG/mAlkhSKKQgg DE1djWUtotR6f/EzSGlWj0ej6NA9KWros8CL+IubBM8iJKZ7zVayT59p0HIr8qLu4KWG dqia24xeI5lVwlqUZXzjG+2NUjAMKWNFVtJNo= |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=U62Q4+UdILDr8BGU/+q+roLGufJvo+p0AJuntKtMlJE=; b=dJaR0kk84FT3rY44Fts8auI3CoAOPfi0uKyZOSXUx6veJQOihI+fZzsJlk+78njZe7 lUr6FcfuKsphqiEaef2gdE9TkpEoDNbaA4cSx8uZbmHVw+tVkEkdwQ7VUCP11xEXiUhp Em0tL2xWQlns1B3OfRCViSN8sXgrAs7Xikfs8t4CKek8FhDnOwfmCeT5gWf5+8iFJIQF AylvnDwt6jkXPo6sfTfcW0GQMim0TnNzV6BCuniyYLU9reb7QWIL76QuZz7iSvMZKUBr AKgduuR4tgRWvLe2mSsraJ1uj5B5gSXTQCQ7LZeFFcHjMx7ekcNjxd6eT1lvd6C3G70y 3Gxg== |
| X-Gm-Message-State | ALoCoQlJsf1hDTl5Gzo3SV7s4WOT8BBhFdOlKQ0QIyIsSI7BatzALidZW10PCHgYr3rfAuZVqOzJFOfk2QUtWdy55NINUPPkYlrlLV435TwhvEMvr9D+u/k= |
| X-Received | by 10.202.217.5 with SMTP id q5mr24798908oig.29.1450136957709; Mon, 14 Dec 2015 15:49:17 -0800 (PST) |
| In-Reply-To | <20151214231420.GA20631@cskk.homeip.net> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.20+ |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:100437 |
Show key headers only | 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
Re: Try: rather than if : Vincent Davis <vincent@vincentdavis.net> - 2015-12-14 16:48 -0700
csiph-web