Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Re[2]: .format won't display my value with 2 decimal places: Why? Date: Mon, 25 Jan 2016 10:31:52 -0700 Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de xHnjWh5oqWdvXyfAsEk+lwAzzS+hJ4iCGhoTW7jyvQwg== 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; 'received:209.85.223': 0.03; 'elements.': 0.05; 'mrab': 0.05; 'used.': 0.05; 'trailing': 0.07; 'positional': 0.09; 'subject:Why': 0.09; 'jan': 0.11; 'exception': 0.13; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'string': 0.17; 'element': 0.18; 'skip:{ 20': 0.18; 'arguments': 0.22; 'am,': 0.23; 'elements': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "doesn't": 0.26; 'equivalent': 0.27; 'message- id:@mail.gmail.com': 0.27; 'arguments,': 0.29; 'raise': 0.29; 'point,': 0.33; 'received:google.com': 0.35; 'fail': 0.35; 'should': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'keyword': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'expect': 0.37; 'received:209': 0.38; 'why': 0.39; 'subject:[': 0.39; 'format': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'worth': 0.67; 'price': 0.69; 'subject:value': 0.84; 'to:name:python': 0.84 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-type; bh=1iWwZnkRm93LwDiN+200sYSYf/0pDyJir7FPsJ7f8Sc=; b=Ird/3m9VLa+H/VCqHShGNcK+6xecC0+EBCIhr82vg8zPA/D69mX/9tsLxzVznwUIQR abn88gWxCY4SEe/aoMHhK/vU8QbFvQSeLgJRmRraLjU52/L5xOFFiK4dxcH6bvO1bCPA 6J5ZSnmIHnesvtAcMap+uXoejr1bFHz4AHFAOZf19ugp+npss03oBU2wK4nal8Dujj0K rde4ujWksagm1wjvzOM/1YxfCKceggRTkYy7/qTRDgG4KD58LIqe8ZioBlO1ixqR8ccf WhZvOYD53Yt1wUZ6zDIvhTTC+lkG2hbDi/uHQIIsfriDn7ppLM1RWqQtBKv1hsLKFfsa k7iw== 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=1iWwZnkRm93LwDiN+200sYSYf/0pDyJir7FPsJ7f8Sc=; b=OysaNlcEi+S+HNXvy2bGUccygsJTzfTIZR6h2MqO9ZLHhp2bQQajvyxVbgSunn9g8D dt1u8pJQZvzY9ROINpGqXrP+TR5ZXZiW3D3S/EoBp62DEoh+oXGf7rMSyoWOaQiaV5z6 D96l1su9IVHhNW5jxKY1bfDuIttasiCKmCMopKo2AADNxE5ID+QuCGVk2P7lrh57gyq/ IHoyAYY9c2vkkLcz+fze5JbTIltX1fTcY7dBLajjG5VX8OKeA5inHUcK0GMBajisLzoD QBPZ9TGnPNW6PkHmveyD0ud/MQpTyf8iKu7eWpC7Agy5hucCVbQHlpXIZH2Kxy8nzYVW zZfw== X-Gm-Message-State: AG10YORp9SrlxaCIun5rhwd7yawhn+/z+NxYPOEHO0XkEQjXgxf5UfKAXaoP5YUoUcEtQ5zsUoTL4hdW4VRZWQ== X-Received: by 10.107.185.6 with SMTP id j6mr18324936iof.111.1453743152189; Mon, 25 Jan 2016 09:32:32 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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:102099 On Mon, Jan 25, 2016 at 10:19 AM, MRAB wrote: > > > On 2016-01-25 16:51:36, "Ian Kelly" wrote: > >> >> Why doesn't str.format raise an exception when passed extra positional >> arguments? >> > That format string uses auto-numbering, and it's equivalent to 'The new > price is {0:.2f}'. > > In general, the positional arguments can be used in any order, and there can > also be keyword arguments, so it would need to remember which arguments had > been used. Would it be worth it? > > Do you really want to insist that the format string always used _all_ of the > arguments? Good point, that makes sense. For example, I would expect this to work: '{0} {2}'.format(*some_list) as long as some_list has three elements. I wouldn't expect it to fail just because the middle element is unused, so why should it fail if there are trailing elements that are unused?