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
probabl
abcd wrote:
> I recently came across a problem where I saw this error:
> "TypeError: unsubscriptable object"
>
> How can I determine if an object is "scriptable" or "unscriptable"?
By trying to apply the subscript operator ('[]'). If it raises a
TypeError, then it's not subscriptable.
But, as La
abcd wrote:
> Richard Brodie wrote:
>
>>subscriptable: supports an indexing operator, like a list does.
>
> doesn't seem to be a builtin function or module...
It's not. Look no further.
> or is that just your
> definition of subscriptable?
It's a correct definition of 'subscriptable' in the c
"abcd" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> doesn't seem to be a builtin function or module...or is that just your
> definition of subscriptable?
Yes, I figured you were just confused. You were using the wrong words,
after all.
--
http://mail.python.org/mailman/list
Larry Bates wrote:
> abcd wrote:
>
>>I recently came across a problem where I saw this error:
>>"TypeError: unsubscriptable object"
>>
>>How can I determine if an object is "scriptable" or "unscriptable"?
>>
>
> Simplest answer is to use isinstance to see if it is a string, list,
> or tuple:
>
>
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!
--
http://mail.python.org/mailman/listinfo/python-list
Richard Brodie wrote:
> subscriptable: supports an indexing operator, like a list does.
Right. You can check this e.g. with
hasattr(x, "__getitem__")
because the __getitem__ method is used for indexing.
Daniel
--
http://mail.python.org/mailman/listinfo/python-list
abcd wrote:
> I recently came across a problem where I saw this error:
> "TypeError: unsubscriptable object"
>
> How can I determine if an object is "scriptable" or "unscriptable"?
>
Simplest answer is to use isinstance to see if it is a string, list,
or tuple:
if isinstance(variable, (str, list
Richard Brodie wrote:
> subscriptable: supports an indexing operator, like a list does.
doesn't seem to be a builtin function or module...or is that just your
definition of subscriptable?
--
http://mail.python.org/mailman/listinfo/python-list
"abcd" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I recently came across a problem where I saw this error:
> "TypeError: unsubscriptable object"
>
> How can I determine if an object is "scriptable" or "unscriptable"?
subscriptable: supports an indexing operator, like a list do
I recently came across a problem where I saw this error:
"TypeError: unsubscriptable object"
How can I determine if an object is "scriptable" or "unscriptable"?
--
http://mail.python.org/mailman/listinfo/python-list
11 matches
Mail list logo