Message170575
format(value) and value.__format__() behave differently even though the documentation says otherwise:
"Note: format(value, format_spec) merely calls value.__format__(format_spec)."
(from http://docs.python.org/library/functions.html?#format )
The difference happens when the format string is unicode. For example:
>>> format(10, u'n')
u'10'
>>> (10).__format__(u'n') # parentheses needed to prevent SyntaxError
'10'
So either the documentation should be changed, or the behavior should be changed to match.
Related to this: neither the "Format Specification Mini-Language" documentation nor the string.Formatter docs seem to say anything about the effect that a unicode format string should have on the return value (in particular, should it cause the return value to be unicode or not):
http://docs.python.org/library/string.html#formatspec
http://docs.python.org/library/string.html#string-formatting
See also issue 15276 (int formatting), issue 15951 (empty format string), and issue 7300 (unicode arguments). |
|
Date |
User |
Action |
Args |
2012-09-16 19:59:51 | chris.jerdonek | set | recipients:
+ chris.jerdonek, docs@python |
2012-09-16 19:59:51 | chris.jerdonek | set | messageid: <1347825591.49.0.625826586182.issue15952@psf.upfronthosting.co.za> |
2012-09-16 19:59:50 | chris.jerdonek | link | issue15952 messages |
2012-09-16 19:59:50 | chris.jerdonek | create | |
|