[issue9805] Documentation on old-style formatting of dicts is overly restrictive
New submission from Ken Basye : >From http://docs.python.org/library/stdtypes.html#string-formatting-operations >: "When the right argument is a dictionary (or other mapping type), then the formats in the string must include a parenthesised mapping key into that dictionary inserted immediately after the '%' character." (with emphasis on 'must' in the HTML, BTW). This isn't correct: "%s" % dict() is a perfectly legal expression with a dictionary as the right argument and no mapping key in the formats. Indeed, if the current doc were correct, there would apparently be no way to format an empty dictionary. How about this one-word fix: "When the right argument is a dictionary (or other mapping type), then the formats in the string may include ..." and so on into the next sentence, and no emphasis on 'may'. P.S. Not sure about the Type of this issue, and it's present in both 2.7 and current 3.X doc. -- assignee: d...@python components: Documentation messages: 115907 nosy: Ken.Basye, d...@python priority: normal severity: normal status: open title: Documentation on old-style formatting of dicts is overly restrictive versions: Python 2.7 ___ Python tracker <http://bugs.python.org/issue9805> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9805] Documentation on old-style formatting of dicts is overly restrictive
Ken Basye added the comment: If someone's going to fix this, perhaps they might consider also adding the following clarification sentence after 'The mapping key selects the value to be formatted from the mapping.' The mapping key is interpreted as a string; a key error is raised if the dictionary does not have a matching string key. I don't think it's worth adding it, but consider this example: >>> d = {2:2, '2':'two'} >>> '%(2)s' % d 'two' -- ___ Python tracker <http://bugs.python.org/issue9805> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9805] Documentation on old-style formatting of dicts is overly restrictive
Ken Basye added the comment: I think Eric is correct; it's a dupe. And I was wrong about not otherwise being able to format an empty dictionary - "%s" % (d,) will always work and is arguably the right thing to do anyway. -- type: behavior -> versions: -Python 3.1, Python 3.2 ___ Python tracker <http://bugs.python.org/issue9805> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com