[Python-Dev] unsubscriptable vs object does not support indexing (original) (raw)
MRAB python at mrabarnett.plus.com
Thu Sep 24 02:20:22 CEST 2009
- Previous message: [Python-Dev] unsubscriptable vs object does not support indexing
- Next message: [Python-Dev] unsubscriptable vs object does not support indexing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Ben Finney wrote:
Steven D'Aprano <steve at pearwood.info> writes:
As far as I can see, in practice, people talk about obj[i] as the item at index i, not the item at subscript i -- the term "subscript" in this context seems to be rare to non-existent except for the error message. Presumably, the same people would also call ‘obj[i]’ the item at key ‘i’, if ‘obj’ is a dictionary. For an object that supports neither indexes nor keys, though, how is Python to know which the user meant? It's a single operation as far as the parser is concerned, so there needs to be a single term for it. That term is “subscript”. Your point about the awkward word “unsubscriptable” is well-taken, though. Perhaps a simple improvement to the message wording: >>> foo = 3 >>> foo[6] Traceback (most recent call last): File "", line 1, in TypeError: 'int' object does not support subscripts >>> foo['spam'] Traceback (most recent call last): File "", line 1, in TypeError: 'int' object does not support subscripts It's called a 'subscript' because conventional mathematical notation uses subscripting. Newbies might be acquainted with the term 'index' from books, where the 'value' is non-numeric. It's a bit unfortunate that dicts have keys+value instead of index+value! :-)
- Previous message: [Python-Dev] unsubscriptable vs object does not support indexing
- Next message: [Python-Dev] unsubscriptable vs object does not support indexing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]