> On Tue, Feb 22, 2011 at 6:01 PM, Steve Holden <steve at holdenweb.com> wrote: >> ... It would appear from tests >> that "{0[X]}".format(...) first tries to convert the string "X" to in >> integer. If it succeeds then __getitem__() is called with the integer as an >> argument, otherwise it is called with the string itself as an argument. Is >> this correct? > > This is addressed in the PEP 3101: > """ > 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. > """ http://www.python.org/dev/peps/pep-3101/ To the other question : > Furthermore, how does one access the key '1' in a format statement? > ~Ethan~ I think, parsing rule already helps to understand the problem with the key like '1'. The PEP also explicitly states that: """ Because keys are not quote-delimited, it is not possible to specify arbitrary dictionary keys (e.g., the strings "10" or ":-]") from within a format string. """ -- Senthil
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4