[issue7951] Should str.format allow negative indexes when used for __getitem__ access?

Terry J. Reedy report at bugs.python.org
Sat Apr 12 04:40:49 CEST 2014


Terry J. Reedy added the comment:

Either leading sign, '+' or '-', cause string interpretation, so I think 'unsigned integer' should be the term in the doc.

>>> '{0[-1]}'.format({'-1': 'neg int key'})
'neg int key'
>>> '{0[+1]}'.format({'+1': 'neg int key'})
'neg int key'
>>> '{0[+1]}'.format([1,2,3])
Traceback (most recent call last):
  File "<pyshell#16>", line 1, in <module>
    '{0[+1]}'.format([1,2,3])
TypeError: list indices must be integers, not str

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7951>
_______________________________________


More information about the Python-bugs-list mailing list