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: Sat, 12 Mar 2016 23:10:07 +1100 Lines: 39 Message-ID: References: <87h9gcxkd3.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de ZHZBroRV6WfZPVshpICFlAggYNJjLoYdBbvnGjJ5XkhA== Return-Path: 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; 'compile-time': 0.07; 'cc:addr:python-list': 0.09; 'subject:which': 0.09; 'way:': 0.09; 'whichever': 0.09; 'python.': 0.11; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instead:': 0.16; 'integers,': 0.16; 'literal.': 0.16; 'need,': 0.16; 'ordinals': 0.16; 'py3': 0.16; 'really?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'subscripting': 0.16; 'unicode.': 0.16; 'wrote:': 0.16; 'string': 0.17; 'byte': 0.18; 'integer': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'ascii': 0.22; 'sat,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'necessary,': 0.29; 'yields': 0.29; '"the': 0.32; 'though.': 0.33; 'values.': 0.33; 'definition': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'unicode': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; '12,': 0.37; 'received:209.85.213': 0.37; 'difference': 0.38; 'received:209': 0.38; 'rather': 0.39; 'subject:The': 0.61; 'complete': 0.63; 'between': 0.65; 'mar': 0.65; 'here': 0.66; 'miss': 0.77; '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=tE0lzKk2X1MX+7mezs53MWK+CD/YsYJt2Tm9ZfGbDDM=; b=IwMvG9hZhOMNpdApMl8YzbAew3XX7NCXp53qqkCnWcWl+AGSYaIrNhI1wRU8p47ywD 39sQA2TiNFFf2EscgSq3iFRyk2vp+lMxcqebDcq5GCFFA7tuLNd08UIFuuRQSvtEmPQd zapyGLy2jNVafpaphNH8RSYUwzdUGqNuFkQeFD1UHHzivQ415KZh0e5ZVPe4dNatfnug 3+73hRAFuL2TZTzrmuk0YmZaXUgYLqVvj/9Qu1YQWutHbjvBICJxqMaJUVG7K6FKTiN2 rbMxQtzNaiJGjfWFOIlnmsMmnK6PiUiah6NlwhoUbFtqzfd3lr3RNfCztFpji9/YOulK WWag== 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=tE0lzKk2X1MX+7mezs53MWK+CD/YsYJt2Tm9ZfGbDDM=; b=k0UbIC73MdZBcPJSLFdW6Alflqg4m1URQQ88Y29qJqJAdworxbA4vJURnrC117uklz xUwPfmiCkhs6Q0r9RVG42mWrA1L5MtJgF3+CFepgaf+0Za5nCHk5avAwG1w1mI+B8fSz hHM/njpvp5T+qNFfhlVXzSWvnDbaKfcm0gMyf2z0Pjybx3S12ZaHXZG8A9ek2dqgswiR EHlZMzQOHkgh6Vgh1EqbIBKzhGDDiHbSttF3cto89t9gmjKllPonZaKVIEiG6pPQu/x8 M+VQAHjByWSKBazcvXn0lCddf1JocZXrzyVmpEPROPWm5Oab+4nSbYF4ixKtocWRz/a7 7ojA== X-Gm-Message-State: AD7BkJJM8Ff7s1J0q1MLOYIN49bVQXbdWK5nfCLtTj8Ma0KNka+YfrchRlD1NHrz1xYoxkLPNGvjnAvaMQ+isw== X-Received: by 10.50.28.105 with SMTP id a9mr9187251igh.94.1457784607970; Sat, 12 Mar 2016 04:10:07 -0800 (PST) In-Reply-To: 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:104694 On Sat, Mar 12, 2016 at 10:08 PM, BartC wrote: >>> You're not mistaken. There are no "character constants" in Python. >>> (Note that the definition would be Unicode codepoints, rather than >>> ASCII values.) I don't often miss them, though. > >> Yes, a complete non-issue. > > > Really? The issue as I see it is this: > > Writing: a=65 generates this byte-code for the right-hand-side: > > LOAD_CONST 1 (65) An integer > > But writing instead: a=ord('A') generates this: > > LOAD_GLOBAL 0 (ord) > LOAD_CONST 1 ('A') A string > CALL_FUNCTION 1 I think the "non-issue" here is the difference between ASCII and Unicode. Either way, there's no way to say "the integer with the codepoint of this character" as a literal. But that's actually not even all that necessary, because subscripting a text string yields one-character strings - you almost never need the ordinals. Subscripting a byte string in Py3 yields integers, so you might need ordinals for ASCII byte values. But you can get them the same way: >>> dis.dis(lambda: b"a"[0]) 1 0 LOAD_CONST 3 (97) 3 RETURN_VALUE >>> dis.dis(lambda: u"a"[0]) 1 0 LOAD_CONST 3 ('a') 3 RETURN_VALUE Whichever one you need, you can get as a compile-time constant. ChrisA