Re: Formatted Integer With Specified Number Of Digits

songbird <[email protected]>
Newsgroups gmane.comp.python.general
Organization the little wild kingdom
Message-ID <[email protected]>
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
-- 
https://mail.python.org/mailman3//lists/python-list.python.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.