Cool that we don't have to quote the string indice. Isn't that ambiguous though?"It's dark. You might be eaten by an [enemy[name]]."
For example: (this uses actual Python formatting, so it looks a little different)
Code: Select all
>>> d2 = {'str' : {'me': 22, 1: 44}, 'me':1}
>>> "{str[me]}".format(**d2)
'22'
(whereas in my example, you might be expecting '44' as your output -- the result of looking up 'me' in the toplevel dictionary, and indexing str by that value; in the context of RenPy, 'me' would correspond to a global variable)
My point? The documentation needs to be clear on this fact, and how to deal with it.
BTW, while I was looking for a good explanation of the intention behind that behaviour, I found this: http://stackoverflow.com/questions/1012 ... -of-python
Which is quite fascinating.
EDIT: Ah, here's an explanation:
-- http://www.python.org/dev/peps/pep-3101/Unlike some other programming languages, you cannot embed arbitrary
expressions in format strings. This is by design - the types of
expressions that you can use is deliberately limited. Only two operators
are supported: the '.' (getattr) operator, and the '[]' (getitem)
operator. The reason for allowing these operators is that they don't
normally have side effects in non-pathological code.
...
It should be noted that the use of 'getitem' within a format string
is much more limited than its conventional usage. In the above example,
the string 'name' really is the literal string 'name', not a variable
named 'name'. The rules for parsing an item key are very simple.
If it starts with a digit, then it is treated as a number, otherwise
it is used as a string.