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: Mon, 11 Jul 2016 19:16:03 -0600 Lines: 37 Message-ID: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de Ml3wczhzTU1Qpcx9qtiAEQyPcEZoT3NNM4yv1KBMoJUg== Return-Path: 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; 'builtin': 0.07; 'consistency.': 0.09; 'degree,': 0.09; 'spec': 0.09; 'def': 0.13; '2016': 0.16; 'formats,': 0.16; 'gregory': 0.16; 'imposing': 0.16; 'include.': 0.16; 'printf-style': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'spec):': 0.16; 'thinking,': 0.16; 'wrote:': 0.16; 'string': 0.17; 'integer': 0.18; 'saying': 0.22; 'parsing': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; 'specify': 0.27; "skip:' 10": 0.28; 'consistency': 0.29; 'skip:_ 10': 0.32; 'class': 0.33; 'third': 0.33; 'lets': 0.33; "skip:' 20": 0.34; 'received:google.com': 0.35; 'could': 0.35; 'but': 0.36; 'cases': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'method': 0.37; 'skip:4 10': 0.38; 'means': 0.39; 'format': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'maximum': 0.61; 'course': 0.62; 'jul': 0.72; 'maths': 0.84; 'to:name:python': 0.84; 'ethan': 0.91; 'furman': 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; bh=heljlIt0ovv89zlO5VI3HINeST9jsIFnDYaTo6cShrE=; b=semeupu03fLP9zemVMGhPaFPEDEj+HQ4Y4oiNeZaUIkuCyoQ1wZWXufd9FAz3ra7MQ ZaOXv6XF4JsFKIaX1gegryw/UxozUrQeubDS5aIrwH4a/Qmd3L3wSmSdU2eN2wXpg4Hk YUUxJsBkLWXcWc/bOxOZ1gmyJQ98plzRhc+6+ulxJzDv8etBa7P6w2LiMdHnUIS+CTdu SkSSD+WH8gn49+lBrGyfr3hkKCUTyr4Kb0H/NXnEToCAqt1TfTko2NPbU9hXqlZJeQB8 OtoO/vFG7UzVCnA8ki9UGvOxVEGFbOoNATLKG4hRXkcTqYaqpohZ5mKyzn3l9MSaWz33 eTeQ== 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; bh=heljlIt0ovv89zlO5VI3HINeST9jsIFnDYaTo6cShrE=; b=abJr90cGf6W8rVRe/e4d0dukaEc0YJ0C/YmKSalTS4NCGXXrjdGCq+uI8Q2QTyC+jP VrHPpe+ZpGXp+bHBqGe3SeLh3MMm19682ZpRpHoC7z0O0kTPOqSfK53HUWWVlvS/s52x Sn2h1QEoJggNoKBg3KciFLn6EYoAyESmUA9TJmKg3mV5NcFow01sy5UTmObm3KLyOCxl eHSWElU6okI5Fjyj8eKkccqrC1C59S+Y4f1zK8PELBN+X8QOAZzxgnUfTRdvkmbGb3XN wqmO0/C7tHPzmn/VXLdg84pjglX/+RJrPaB4MMaJZQxbg1H2GRPgVenBJX+ZpV7LmWlC QitA== X-Gm-Message-State: ALyK8tLRaWAXua44FmGcbwXYyImvSdSefRiVDJD8rTS2gupLfN4sJK4eaVrqPGcb4f1c7WOPqdaRAX+qRtA1IA== X-Received: by 10.202.92.138 with SMTP id q132mr10492354oib.54.1468286203410; Mon, 11 Jul 2016 18:16:43 -0700 (PDT) In-Reply-To: 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> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Xref: csiph.com comp.lang.python:111307 On Mon, Jul 11, 2016 at 5:47 PM, Gregory Ewing wrote: > Ethan Furman wrote: >> >> I will readily admit to not having a maths degree, and so of course to me >> saying the integer 123 has a precision of 5, 10, or 99 digits seems like >> hogwash to me. > > > Seems to me insisting that the number after the dot be > called "precision" in all cases is imposing a foolish > consistency. > > There's a third thing that %-formats use it for as well: > for a string it means the maximum number of characters > to include. > > To my way of thinking, the format string just lets you > specify uop to two numbers, the interpratation or wnich > is up to toe format concerned. The builtin types strive for consistency with each other and with printf-style formats, but ultimately the parsing of the format spec is entirely at the whim of the __format__ method of the type being formatted. You could make it a Turing-complete mini-language if you liked. py> class Foo: ... def __format__(self, spec): ... return str(eval(spec)(self)) ... py> '{:id}'.format(Foo()) '139869336090384' py> '{:repr}'.format(Foo()) '<__main__.Foo object at 0x7f35de17b7b8>' py> '{:lambda x: x == 42}'.format(Foo()) 'False'