New submission from Pete Wicken <[email protected]>:
When formatting an integer as a hexadecimal value, the '#' alternate form
modifier inserts a preceding '0x'.
If this is used in combination with padding modifiers, the '0x' is counted as
part of the overall width, which does not feel like the natural behaviour as
extra calculation is required to get the correct post '0x' precision.
Example:
In [7]: f'{num:04x}'
Out[7]: '0800'
In [8]: f'{num:#04x}'
Out[8]: '0x800'
To get the hexadecimal representation padded to 4 digits, you have to account
for the preceding 0x:
In [10]: f'{num:#06x}'
Out[10]: '0x0800'
----------
messages: 355767
nosy: Wicken
priority: normal
severity: normal
status: open
title: String format for hexadecimal notation breaks padding with alternative
form
type: behavior
versions: Python 3.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38657>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com