Message262109
> 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. |
|
Date |
User |
Action |
Args |
2016-03-21 09:02:17 | ezio.melotti | set | recipients:
+ ezio.melotti, vstinner, eric.smith, docs@python, serhiy.storchaka, wolma, Manvi B |
2016-03-21 09:02:17 | ezio.melotti | set | messageid: <1458550937.63.0.494399019322.issue26506@psf.upfronthosting.co.za> |
2016-03-21 09:02:17 | ezio.melotti | link | issue26506 messages |
2016-03-21 09:02:17 | ezio.melotti | create | |
|