[issue5237] Allow auto-numbered replacement fields in str.format() strings

Nick Coghlan report at bugs.python.org
Tue Mar 10 10:34:22 CET 2009


Nick Coghlan <ncoghlan at gmail.com> added the comment:

It may also be worth explicitly stating the following in the docs: "Note
that automatically numbered and explcitly namged/numbered replacement
fields cannot be mixed in a single format string". (This could probably
be relegated to a footnote).

This proposal is also significantly better defined than the rather
bizarre behaviour seen in the equivalent situation with %-formatting:

>>> "%s %(name)s" % dict(name="Hmm")
"{'name': 'Hmm'} Hmm"

>>> "%s %(name)s %s" % dict(name="Hmm")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string

>>> "%s %(name)s %s" % (dict(name="Hmm"), "dodgy")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: format requires a mapping

----------
message_count: 21.0 -> 22.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5237>
_______________________________________


More information about the Python-bugs-list mailing list