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.

classification
Title: format() doesn't parse str.
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: eric.smith, ezio.melotti, umedoblock
Priority: normal Keywords:

Created on 2012-02-08 18:44 by umedoblock, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg152897 - (view) Author: umedoblock (umedoblock) Date: 2012-02-08 18:44
format() mis understaning.
please pay attention to [0], [x].

>>> d = {0: "a", "0": "A"}
>>> 'd[0] = {0[0]}'.format(d)
'd[0] = a'
>>> 'd[0] = {0["0"]}'.format(d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: '"0"'
>>> d2 = {"x": 100}
>>> 'd2[x] = {0[x]}'.format(d2)
'd2[x] = 100'
msg152902 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2012-02-08 19:39
This is working as defined in PEP 3101: it calls PySequence_GetItem() or PyObject_GetItem() on the value inside the brackets. There is indeed no item in d that is the string "0" (including the quotes).
History
Date User Action Args
2022-04-11 14:57:26adminsetgithub: 58179
2012-02-08 19:39:34eric.smithsetstatus: open -> closed
messages: + msg152902

assignee: eric.smith
resolution: not a bug
stage: resolved
2012-02-08 18:45:30ezio.melottisetnosy: + eric.smith
2012-02-08 18:44:22umedoblockcreate