tags:

views:

1543

answers:

4

Which types of objects fall into the domain of "subscriptable"?

+14  A: 

It basically means that the object implements the __getitem__() method. In other words, it describes objects that are "containers", meaning they contain other objects. This includes lists, tuples, and dictionaries.

mipadi
Incredible. What you describe is an "indexable" or "subscriptable" object, not a "scriptable" object, which is a valid term.
ΤΖΩΤΖΙΟΥ
A: 

I think you mean "subscriptable", in which case mipadi's definition is spot-on!

Dan
Dan, your answer should be a comment to the question.
ΤΖΩΤΖΙΟΥ
A: 

A scriptable object is an object that records the operations done to it and it can store them as a "script" which can be replayed.

For example, see: Application Scripting Framework

Now, if Alistair didn't know what he asked and really meant "subscriptable" objects (as edited by others), then (as mipadi also answered) this is the correct one:

A subscriptable object is any object that implements the __getitem__ special method (think lists, dictionaries).

ΤΖΩΤΖΙΟΥ
Note that I'm replying to the original question about "scriptable" objects, not "subscriptable" as edited by others, not Alistair. I really would like Alistair to comment.
ΤΖΩΤΖΙΟΥ
Ok, upvoted. But if you want the Peer Pressure badge, let me know :D
Federico Ramponi
Ah, a new badge for my collection! :) Just kidding, obviously. The only thing that justified the editing of the question was that Alistair chose an answer; I still am not sure if Alistair was sure about choosing.
ΤΖΩΤΖΙΟΥ
You do know that up/downvoting means "helpful/not helpful" in relation to the question, right? It doesn't mean "I agree/disagree" or "I like it/I don't like it" or even "I like you/I don't like you". In the end it is I that will get blamed for overbloated ego…
ΤΖΩΤΖΙΟΥ
A: 

Off the top of my head, the following are the only built-ins that are subscriptable:

string:  "foobar"[3] == "b"
tuple:   (1,2,3,4)[3] == 4
list:    [1,2,3,4][3] == 4
dict:    {"a":1, "b":2, "c":3}["c"] == 3

But mipadi's answer is correct; any class that implements __getitem__ is subscriptable

Dan