How to determine an object is "scriptable"

Peter Hansen peter at
Thu Mar 30 18:30:37 CEST 2006

abcd wrote:
> Daniel Evers wrote:
>>Right. You can check this e.g. with
>>        hasattr(x, "__getitem__")
>>because the __getitem__ method is used for indexing.
> Thanks...that is what I was looking for!

Maybe, but it's not a particularly Pythonic way of doing it.  Better is 
probably something like this:

     x_is_subscriptable = True
except TypeError:
     x_is_subscriptable = False


More information about the Python-list mailing list