[New-bugs-announce] [issue15952] format(value) and value.__format__() behave differently with unicode format

Chris Jerdonek report at bugs.python.org
Sun Sep 16 21:59:51 CEST 2012

New submission from Chris Jerdonek:

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')
>>> (10).__format__(u'n')  # parentheses needed to prevent SyntaxError

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):


See also issue 15276 (int formatting), issue 15951 (empty format string), and issue 7300 (unicode arguments).

assignee: docs at python
components: Documentation
messages: 170575
nosy: cjerdonek, docs at python
priority: normal
severity: normal
status: open
title: format(value) and value.__format__() behave differently with unicode format
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list