Curious Omission In New-Style Formats
Ian Kelly
ian.g.kelly at gmail.com
Mon Jul 11 15:27:16 EDT 2016
On Mon, Jul 11, 2016 at 12:54 PM, Terry Reedy <tjreedy at udel.edu> 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'
More information about the Python-list
mailing list