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


Groups > comp.lang.python > #38153

Re: LBYL vs EAFP

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'puts': 0.07; 'check.': 0.09; 'sake': 0.09; 'cases': 0.15; 'caveat': 0.16; 'ellipsis': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'indent': 0.16; 'wrote:': 0.17; 'code,': 0.18; 'feb': 0.19; 'import': 0.21; "i'd": 0.22; 'raise': 0.24; 'header :In-Reply-To:1': 0.25; 'am,': 0.27; 'handling': 0.27; 'message- id:@mail.gmail.com': 0.27; 'about.': 0.29; "d'aprano": 0.29; 'steven': 0.29; 'function': 0.30; 'error': 0.30; 'code': 0.31; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'previous': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'further': 0.61; 'information': 0.63; 'more': 0.63; '2013': 0.84; 'conditions,': 0.84; 'number):': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=fl5n1uegVxjsKTGb70Y5qtYQQ9jgSCLnHErU2BfkRFY=; b=wkKR3nSD+XBJFqFr+ScaTr2fJ54e29b+CQb1gv4RdEZMxrPzfxoiDNt5JkBF8ffg/w FzLL8jqb+YSqXHIktshPa6HOmX5Yt9zt/lRgIQerKx3XpejJLMG5UShCtU1865rdJBAH 0762tpPymPoKxgeNC20ayjQaG/V5DszrJoaEBcmBdDxJDb7EPcqTX5TyhzIR6rKoGy7K NDuzYY7IIcErHnfOR/WYJALixeXszfBZvo/XeLC1qTenEUseG05ndU8snNSIxsYWz/CQ 0BFqeB6oBy6B92fMrxmoQMoqGZSGh3GUBTvibnyI0dyFVI5THejWAh7GA7UUzAM9hXcp SJjg==
MIME-Version 1.0
X-Received by 10.224.31.205 with SMTP id z13mr19094191qac.76.1360025118334; Mon, 04 Feb 2013 16:45:18 -0800 (PST)
In-Reply-To <5110415c$0$29986$c3e8da3$5496439d@news.astraweb.com>
References <5110415c$0$29986$c3e8da3$5496439d@news.astraweb.com>
Date Tue, 5 Feb 2013 11:45:18 +1100
Subject Re: LBYL vs EAFP
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1343.1360025121.2939.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360025121 news.xs4all.nl 6842 [2001:888:2000:d::a6]:51474
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38153

Show key headers only | View raw


On Tue, Feb 5, 2013 at 10:16 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>     from numbers import Number
>     if isinstance(x, Number):
>         ...
>     else:
>         raise TypeError
>
>
> or Ask Forgiveness:
>
>     x + 0
>     ...
>
>
> where in both cases the ellipsis ... is the code I actually care about.

Caveat to my previous post: I would NOT indent the function body for
the sake of this check. I'd negate it:

if not isinstance(x, Number): raise TypeError

(hopefully with further information in the TypeError). I don't like
the code style that puts conditions, then more code, then error
handling - I prefer to fail-and-bail.

ChrisA

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


Thread

LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 10:16 +1100
  Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 10:38 +1100
    Re: LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 03:52 +0000
      Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 16:19 +1100
  Re: LBYL vs EAFP Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-04 16:46 -0700
    Re: LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 04:52 +0000
      Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 16:20 +1100
        Re: LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 06:31 +0000
          Re: LBYL vs EAFP Pete Forman <petef4+usenet@gmail.com> - 2013-02-05 09:49 +0000
            Re: LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 23:04 +1100
              Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 23:25 +1100
      Re: LBYL vs EAFP Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-04 22:40 -0700
  Re: LBYL vs EAFP Dave Angel <davea@davea.name> - 2013-02-04 18:55 -0500
  Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 11:45 +1100
  Re: LBYL vs EAFP Ethan Furman <ethan@stoneleaf.us> - 2013-02-04 16:26 -0800
  Re: LBYL vs EAFP Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-05 01:00 +0000
  Re: LBYL vs EAFP Terry Reedy <tjreedy@udel.edu> - 2013-02-05 02:53 -0500

csiph-web