Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Torrie Newsgroups: comp.lang.python Subject: Re: Curious Omission In New-Style Formats Date: Mon, 11 Jul 2016 14:06:24 -0600 Lines: 24 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=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 2Vp6WIagM9moa6nsFtkGUgJB+spWXnQAr0kwkiq0gFTQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.067 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'width': 0.07; '2016': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'hex': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'wrote:': 0.16; 'meant': 0.22; 'occurs': 0.22; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "i've": 0.25; 'header :User-Agent:1': 0.26; 'raw': 0.27; 'specify': 0.27; "i'm": 0.30; 'usually': 0.33; 'int': 0.33; 'message-id:@gmail.com': 0.34; 'case,': 0.34; "skip:' 20": 0.34; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:org': 0.37; 'sure': 0.39; 'format': 0.39; 'does': 0.39; 'received:192': 0.39; 'subject:-': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'field': 0.60; 'ever': 0.60; 'challenge': 0.61; 'charset:windows-1252': 0.62; '>>>>>': 0.66; 'wanting': 0.66; 'jul': 0.72; 'improvement': 0.93 X-Virus-Scanned: amavisd-new at torriefamily.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 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:111289 On 07/11/2016 01:27 PM, Ian Kelly wrote: > On Mon, Jul 11, 2016 at 12:54 PM, Terry Reedy wrote: >> In any case, I think it an improvement to say that '0x00123' has a field >> width of 7 rather than a 'precision' of 5. >> >>>>> '{:#07x}'.format(0x123) # specifiy field width >> '0x00123' >>>>> "%#0.5x" % 0x123 # specify int precision >> '0x00123' > > It occurs to me now that this does create a challenge if the format is > meant to support negative numbers as well: > >>>> '%#0.5x' % -0x123 > '-0x00123' >>>> '{:#07x}'.format(-0x123) > '-0x0123' I'm not sure I've ever seen a negative hex number in the wild. Usually when I view a number in hex I am wanting the raw representation. -0x123 with a width of 7 would be 0xFFEDD