This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients Manvi B, docs@python, eric.smith, ezio.melotti, serhiy.storchaka, vstinner, wolma
Date 2016-03-21.09:02:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458550937.63.0.494399019322.issue26506@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2016-03-21 09:02:17ezio.melottisetrecipients: + ezio.melotti, vstinner, eric.smith, docs@python, serhiy.storchaka, wolma, Manvi B
2016-03-21 09:02:17ezio.melottisetmessageid: <1458550937.63.0.494399019322.issue26506@psf.upfronthosting.co.za>
2016-03-21 09:02:17ezio.melottilinkissue26506 messages
2016-03-21 09:02:17ezio.melotticreate