Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Wed, 23 Mar 2016 12:21:50 +1100 Lines: 29 Message-ID: References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> <56f09973$0$1601$c3e8da3$5496439d@news.astraweb.com> <56f1ee00$0$1608$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de javzynf4s5fzSt5xq9BhdgcB/c4rV7AYI/clPxKvE0Xw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'float': 0.05; 'false,': 0.07; 'cc:addr:python-list': 0.09; 'arg': 0.09; 'str,': 0.09; 'subject:which': 0.09; 'tuple': 0.09; 'typeerror:': 0.09; 'exception': 0.13; 'wed,': 0.15; '"hello': 0.16; '2016': 0.16; '23,': 0.16; 'advice,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mean,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sense:': 0.16; 'subject:?)': 0.16; 'wrote:': 0.16; 'bytes': 0.18; 'mechanism': 0.18; '>>>': 0.20; 'library': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '"",': 0.22; 'appears': 0.23; '(or': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'str': 0.29; 'raise': 0.29; "d'aprano": 0.33; 'rule': 0.33; 'steven': 0.33; 'traceback': 0.33; 'file': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'asking': 0.35; 'should': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209': 0.38; 'still': 0.40; 'subject:The': 0.61; 'mar': 0.65; 'yourself': 0.73; 'chrisa': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=zBhxmfjZfa6Bjgev6+qX457BCKduycQIUy1+JLvbYEQ=; b=ZdIEucl/FDND6/s57uisfR1zBT1+3Gy7Er95u/au01PqyOgQZYq7zLlSB+RrwnTcgI w3UCos/D8ByCzrr50S6YPeOiBxZ2h6wsQreQVbGGu5YrOoM8+wKUuZvC0HJGlooIdxe/ gTOXUwJxHcH/ZvTZXQokxc5OP9tJJVuU6r8pNQQMptKGfYLet3y0Hc2dnCx+rOWFRvr+ wiywaV01fKHxBV4yN5rLSUvPKvoibxwFkoZamOciXpBkt4hEjd1Mu19TlPuGTTKhKdkn rzvBLj56sMiNH/CdO7WRVwcxrdAXXpkbYwvlduGsQiAq9+7U3c3aykhQITJvTxxhNKJo CnOw== 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:date :message-id:subject:from:cc; bh=zBhxmfjZfa6Bjgev6+qX457BCKduycQIUy1+JLvbYEQ=; b=Iv9foz67Nu9RHGBoqAahymLnfprow7ZVIDdUvxNu6n7ZxYkp5SlkP56oR9t4UISxCi OsK1dgWc1LXse3E86xzrnCRp1OBXfLJn22Fkta6/m42vLs7nCWQgP8dyOQJ0mv4UlC1e S0P57IS8hBHcXu9IrbYl742lz+D3oBHl6Uj8fW4iYQV0OEz/J5Jywn5aXgbRH8JXh/Sj 2TqdNTtZfuuf2sLrHyxTr+NF6rLEECvHxK4nb1LVkoISGdIP1xMUM/O3s6u0d2/xoKRV +8lt70HGDx9xQN9AqfDiS6kTmzzRpQ4PhDvMXodsZ8ds8nzfBeJtf5BUBvIvK1HbaCSb 64rg== X-Gm-Message-State: AD7BkJJZ8H+6a/sZcyJ7zLEZmMgAf3H7/RJ77Ve08/sSYiia3d3KXDoKb8T1MxPQZO0Hzoo1WJemq6sLu3rp+A== X-Received: by 10.50.137.35 with SMTP id qf3mr630734igb.92.1458696111019; Tue, 22 Mar 2016 18:21:51 -0700 (PDT) In-Reply-To: <56f1ee00$0$1608$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105505 On Wed, Mar 23, 2016 at 12:14 PM, Steven D'Aprano wrote: >> I mean, is a function allowed to still return True or False, or just >> False? (Or perhaps just nothing if the exception mechanism can signal >> either.) > > > You can answer this question yourself by looking at what functions are > provided in the standard library and built-ins: > > py> "hello world".find("goodbye") > -1 > py> "hello world".startswith("goodbye") > False To add to the "experiment" advice, a general rule of thumb: Any function/method that appears to be asking a yes/no question should be happy to return True/False for the two answers. It can still raise if the question doesn't make sense: >>> "hello world".startswith(3.14159) Traceback (most recent call last): File "", line 1, in TypeError: startswith first arg must be str or a tuple of str, not float >>> "hello world".startswith(b"\x41") Traceback (most recent call last): File "", line 1, in TypeError: startswith first arg must be str or a tuple of str, not bytes ChrisA