Eric V. Smith <e...@trueblade.com> added the comment:

"""
>>> d = {"{0}": "spam"}
>>> # a matched pair of braces. What's inside is considered markup.
... 
>>> "{0}".format(d)
"{'{0}': 'spam'}"
>>> # a matched pair of braces. Inside is a matched pair of braces, and what's 
>>> inside of that is not considered markup.
"""

I'm not sure what' you're getting at. "{0}" (which is indeed "markup") is 
replaced by str(d), which is "{'{0}': 'spam'}".

"""
... 
>>> "{0[{0}]}".format(d)
'spam'
>>> 
"""

Again, I'm not sure what you're getting at. The inner "{0}" is not interpreted 
(per the PEP). So the entire string is replaced by d['{0}'], or 'spam'.

Let me try to explain it again. str.format() parses the string, looking for 
matched sets of braces. In your last example above, the very first character 
'{' is matched to the very last character '}'. They match, in sense that all of 
the nested ones inside match. Once the markup is separated from the character 
data, the interpretation of what's inside the markup is then done. In this 
example, there is no character data.

I apologize if I'm explaining this poorly.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12014>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to