Author eric.smith
Recipients Ben.Wolfson, eric.araujo, eric.smith, mark.dickinson, petri.lehtinen, r.david.murray
Date 2011-06-03.22:52:04
SpamBayes Score 1.82239e-06
Marked as misclassified No
Message-id <1307141525.34.0.40216674519.issue12014@psf.upfronthosting.co.za>
In-reply-to
Content
"""
>>> 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.
History
Date User Action Args
2011-06-03 22:52:05eric.smithsetrecipients: + eric.smith, mark.dickinson, eric.araujo, r.david.murray, Ben.Wolfson, petri.lehtinen
2011-06-03 22:52:05eric.smithsetmessageid: <1307141525.34.0.40216674519.issue12014@psf.upfronthosting.co.za>
2011-06-03 22:52:04eric.smithlinkissue12014 messages
2011-06-03 22:52:04eric.smithcreate