[New-bugs-announce] [issue7951] Should str.format allow negative indexes when used for __getitem__ access?
Eric Smith
report at bugs.python.org
Thu Feb 18 00:54:19 CET 2010
New submission from Eric Smith <eric at trueblade.com>:
It surprised me that this doesn't work:
>>> "{0[-1]}".format('fox')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: string indices must be integers
I was expecting it to be equivalent to:
>>> "{0[2]}".format('fox')
'x'
I don't think there's any particular reason this doesn't work. It would, however break the following code:
>>> "{0[-1]}".format({'-1':'foo'})
'foo'
But note that this doesn't work currently:
>>> "{0[1]}".format({'1':'foo'})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 1
----------
assignee: eric.smith
components: Interpreter Core
keywords: easy
messages: 99482
nosy: eric.smith
priority: normal
severity: normal
status: open
title: Should str.format allow negative indexes when used for __getitem__ access?
type: feature request
versions: Python 2.7, Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7951>
_______________________________________
More information about the New-bugs-announce
mailing list