list indices must be integers or slices, not str

Frank Millman frank at chagford.com
Thu Jul 21 04:32:03 EDT 2022


On 2022-07-20 4:45 PM, Chris Angelico wrote:
> On Wed, 20 Jul 2022 at 23:50, Peter Otten <__peter__ at web.de> wrote:
>>
>> I found
>>
>> https://peps.python.org/pep-3101/
>>
>> """
>> PEP 3101 – Advanced String Formatting
>> ...
>> An example of the ‘getitem’ syntax:
>>
>> "My name is {0[name]}".format(dict(name='Fred'))
>>
>> 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.
>>
> 
> Cool. I think this is a good justification for a docs patch, since
> that really should be mentioned somewhere other than a historical
> document.
> 
> ChrisA

I have submitted the following -

https://github.com/python/cpython/issues/95088

Frank


More information about the Python-list mailing list