Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Curious Omission In New-Style Formats Date: Sun, 10 Jul 2016 01:21:40 -0600 Lines: 33 Message-ID: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de VJl3x/NmJ4Q7Nmq1Kpz6fwHG3ZEZhFar+7WyeGp1+szg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'ignored': 0.05; 'valueerror:': 0.07; 'width': 0.07; 'integers': 0.09; 'separately': 0.09; 'width.': 0.09; '2016': 0.16; 'doesn\xe2\x80\x99t': 0.16; 'formats,': 0.16; 'new-style': 0.16; 'printf-style': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'specifier': 0.16; 'wrote:': 0.16; 'integer': 0.18; '>>>': 0.20; '"",': 0.22; 'lawrence': 0.22; 'sat,': 0.23; 'specified': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'sense': 0.26; 'skip:" 20': 0.26; 'message- id:@mail.gmail.com': 0.27; 'specify': 0.27; 'pep': 0.29; "i'm": 0.30; 'e.g.': 0.30; 'changed': 0.33; 'traceback': 0.33; "skip:' 20": 0.34; 'file': 0.34; 'except': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'itself': 0.38; 'sure': 0.39; 'format': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'field': 0.60; 'per': 0.62; 'lose': 0.63; 'account': 0.66; 'jul': 0.72; '3101': 0.84; 'to:name:python': 0.84; 'reasoning': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=6Kodne4xPocxFcI6uRKOIhMgO9rprytZi3by9ZH3SUo=; b=uVl6C3XKJCK8xNIDa656ubV2CxrelZrkgdy8GfUDNwxnKDW8Jnk/rxQmxg916icdw3 K+oQlXJyJUATwZvgPciCGU6TfkIqsoO7m02ACMsIQcCcl9bry6pc+mFBDvORKb2O7KUd HBZAcmQwoFP6Ylin6zdN4+a576qYlmr5OwRhI2OJsiFah9q2qctAWNGr6z7/aUz1jo9h Ebei1d4Ik+cOfcNJHhrApfSrk2zpSOoNRdiAI+BnYps+1P/w7D1yJsh2U1eLSXxxPiMs 1umNY9xQlhzBlgANFt8D/AYL6AUdf0UGYjGD/Zwx6zTSq5+cyuBJWlw7kn/k/+lX4V5W x7tg== 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-transfer-encoding; bh=6Kodne4xPocxFcI6uRKOIhMgO9rprytZi3by9ZH3SUo=; b=gYXu5kpEh9VqxdaqIBWJ7GDYaEGFlMVgiTiZD87WDc4n9PFpmGUnTGn6aTaogSipNT pr+0Adw/1J4QYqYAZYY4RtZ3nUPg4x2+MsDCSBaSC8eIcIBzfP3cQT+TMYvkNi8Ew24U L5Aqzowr7eVtrGVCG48zhRbghm2cEMvsAZz0m1Ecijp5cmu4QdKJT4wW/33lw/jFOgK8 UNWEDGyfp7csRjM1ynYD996Jmd9i9UDEFF/w8zhRF6LguwEQjMe+yBrAGnh4UY3E5klk pMz9YSoVABxCUQiw7US9+vVNYuB7+5isAFC1zIwBoySW91Vf+g//fdJTrAsRa5D2qzk0 sJzA== X-Gm-Message-State: ALyK8tLPb7psvt7Br/sMUIgjvNAI8b6ATIKSs/kzeZKzRtlacsyo3LNaE5NjQ/OGruLWYahhznHs4pUgkLzjqA== X-Received: by 10.202.80.78 with SMTP id e75mr6452567oib.91.1468135340249; Sun, 10 Jul 2016 00:22:20 -0700 (PDT) In-Reply-To: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> Xref: csiph.com comp.lang.python:111237 On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D=E2=80=99Oliveiro wrote: > In printf-style formats, you can specify the number of digits for an inte= ger separately from the field width. E.g. > > >>> "%#0.5x" % 0x123 > '0x00123' > > but not in new-style formats: > > >>> "{:#0.5x}".format(0x123) > Traceback (most recent call last): > File "", line 1, in > ValueError: Precision not allowed in integer format specifier > > The field width itself doesn=E2=80=99t give the right number of digits in= this case: > > >>> "{:#05x}".format(0x123) > '0x123' > > because you lose 2 characters for the =E2=80=9C0x=E2=80=9D prefix. So add 2 to the field width to account for the fixed-size prefix. >>> '{:#07x}'.format(0x123) '0x00123' It's specified in PEP 3101 that the precision is ignored for integer conversions. Apparently that changed from "ignored" to "not allowed" in 3.1, as per the documentation. I'm not sure what the reasoning was, except perhaps that precision doesn't really make sense for integers in the first place.