Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #197569

Re: Formatted Integer With Specified Number Of Digits

From songbird <songbird@anthive.com>
Newsgroups comp.lang.python
Subject Re: Formatted Integer With Specified Number Of Digits
Date 2025-10-19 10:01 -0400
Organization the little wild kingdom
Message-ID <ci7fsl-dj2.ln1@anthive.com> (permalink)
References <10d23rk$2bc2b$1@dont-email.me>

Show all headers | View raw


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 "<python-input-10>", line 1, in <module>
>         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 "<python-input-13>", line 1, in <module>
>         "{:#0.3x}".format(2)
>         ~~~~~~~~~~~~~~~~~^^^
>     ValueError: Precision not allowed in integer format specifier
>
> Why not?


  https://github.com/tpauldike/printf


  songbird

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Formatted Integer With Specified Number Of Digits Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-10-19 07:26 +0000
  Re: Formatted Integer With Specified Number Of Digits Gilmeh Serda <gilmeh.serda@nothing.here.invalid> - 2025-10-19 09:17 +0000
  Re: Formatted Integer With Specified Number Of Digits songbird <songbird@anthive.com> - 2025-10-19 10:01 -0400
    Re: Formatted Integer With Specified Number Of Digits Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-10-19 21:39 +0000
  Re: Formatted Integer With Specified Number Of Digits Paul Rubin <no.email@nospam.invalid> - 2025-10-24 01:14 -0700
    Re: Formatted Integer With Specified Number Of Digits Alan Bawden <alan@csail.mit.edu> - 2025-10-24 06:38 -0400

csiph-web