Ezio Melotti added the comment:
> The documentation for hex() doesn't look the bests place for examples
> of using string formatting. I think it is enough to add short
> references to corresponding formatting codes.
I think those examples take too much space compared to the actual docs of the
functions.
I can think of 3 possible solutions:
1) keep the examples but condense them so that they don't take so much space:
>>> n = 255
>>> f'{n:#x}', format(n, '#x'), '%#x' % n
('0xff', '0xff', '0xff')
>>> f'{n:x}', format(n, 'x'), '%x' % n
('ff', 'ff', 'ff')
>>> f'{n:X}', format(n, 'X'), '%X' % n
('FF', 'FF', 'FF')
or
>>> '%#x' % 255, '%x' % 255, '%X' % 255
('0xff', 'ff', 'FF')
>>> format(255, '#x'), format(255, 'x'), format(255, 'X')
('0xff', 'ff', 'FF')
>>> f'{255:#x}', f'{255:x}', f'{255:X}'
('0xff', 'ff', 'FF')
(the latter should only go in 3.6 though)
2) add a direct link to
https://docs.python.org/3/library/string.html#format-examples where there are
already some examples (more can be added if needed);
3) add a single footnote for all 3 functions that includes examples using
old/new string formatting and f-strings, mentions the fact that # can be used
to omit the prefix and the fact that b/o/x and B/O/X can be used for lowercase
and uppercase output.
FWIW I don't think that performances matter too much in this case, but I also
dislike hex(value)[2:] and agree it should not be mentioned.
----------
nosy: +ezio.melotti
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue26506>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com