Path: csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: songbird Newsgroups: comp.lang.python Subject: Re: Formatted Integer With Specified Number Of Digits Date: Sun, 19 Oct 2025 10:01:16 -0400 Organization: the little wild kingdom Lines: 40 Message-ID: References: <10d23rk$2bc2b$1@dont-email.me> Reply-To: songbird MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 19 Oct 2025 14:05:18 +0000 (UTC) Injection-Info: dont-email.me; posting-host="06273731fbb4477d307ba5635df1b458"; logging-data="2672981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yjRA/mNuIfGPZjoOOiENuYaLYQ7aEEp4=" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:489D3r2RKReuPYc6+Q8aZM6PeOo= Xref: csiph.com comp.lang.python:197569 Lawrence D’Oliveiro wrote: > Formatting an integer with 3 digits, excluding base specifier: > > >>> "%#0.3x" % 2 > '0x002' > > No equivalent to this in any of the other ways that Python allows for > formatting: > > >>> format(2, "#03x") > '0x2' > > (Not what I want) > > >>> format(2, "#0.3x") > Traceback (most recent call last): > File "", line 1, in > format(2, "#0.3x") > ~~~~~~^^^^^^^^^^^^ > ValueError: Precision not allowed in integer format specifier > > >>> "{:#03x}".format(2) > '0x2' > > (Not what I want) > > >>> "{:#0.3x}".format(2) > Traceback (most recent call last): > File "", line 1, in > "{:#0.3x}".format(2) > ~~~~~~~~~~~~~~~~~^^^ > ValueError: Precision not allowed in integer format specifier > > Why not? https://github.com/tpauldike/printf songbird