468,306 Members | 1,432 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,306 developers. It's quick & easy.

Difference between unindexable and unsubscriptable

What is the difference between "object is unindexable" and "object is
unsubscriptable"?

I would like to test if an object can accept: obj[0]
>>from sets import Set
Set([1,2])[0]
TypeError: unindexable object
>>3[0]
TypeError: unsubscriptable object

It seems like each of these errors can be replaced with a single type error.
Oct 11 '06 #1
5 4157
Jackson wrote:
What is the difference between "object is unindexable" and "object is
unsubscriptable"?

I would like to test if an object can accept: obj[0]
>>from sets import Set
>>Set([1,2])[0]
TypeError: unindexable object
>>3[0]
TypeError: unsubscriptable object

It seems like each of these errors can be replaced with a single type error.
the message string is not part of the error type, and may change between
versions. just catch the TypeError and be done with it.

</F>

Oct 11 '06 #2
Jackson <ja*****@hotmail.comwrites:
I would like to test if an object can accept: obj[0]
Then do so. Use the object in the way you want to use it, and catch
any exceptions that you want to handle.
>>from sets import Set
>>Set([1,2])[0]
TypeError: unindexable object
>>3[0]
TypeError: unsubscriptable object

It seems like each of these errors can be replaced with a single
type error.
Well, they are both merely instances of TypeError, just with a
different message. Catching 'TypeError' will catch either of them.

I agree, though, that it would be preferable to have the same message
for these two cases that appear to be saying the same thing.

--
\ "The trouble with eating Italian food is that five or six days |
`\ later you're hungry again." -- George Miller |
_o__) |
Ben Finney

Oct 11 '06 #3
On 10/11/06, Ben Finney <bi****************@benfinney.id.auwrote:
Jackson <ja*****@hotmail.comwrites:
I would like to test if an object can accept: obj[0]

Then do so. Use the object in the way you want to use it, and catch
any exceptions that you want to handle.
I'm trying to learn about style conventions in Python. How would use
of getattr compare?

-- Theerasak
Oct 11 '06 #4
"Theerasak Photha" <ha********@gmail.comwrites:
On 10/11/06, Ben Finney <bi****************@benfinney.id.auwrote:
Jackson <ja*****@hotmail.comwrites:
I would like to test if an object can accept: obj[0]
Then do so. Use the object in the way you want to use it, and catch
any exceptions that you want to handle.

I'm trying to learn about style conventions in Python. How would use
of getattr compare?
I'm having trouble knowing what you need explained.

You have available to you an interactive Python interpreter, and the
documentation. Can you show us some sessions in the interpreter that
you still find confusing after you read the relevant documentation?

--
\ "When I get new information, I change my position. What, sir, |
`\ do you do with new information?" -- John Maynard Keynes |
_o__) |
Ben Finney

Oct 11 '06 #5
On 10/11/06, Ben Finney <bi****************@benfinney.id.auwrote:
I'm trying to learn about style conventions in Python. How would use
of getattr compare?

I'm having trouble knowing what you need explained.

You have available to you an interactive Python interpreter, and the
documentation. Can you show us some sessions in the interpreter that
you still find confusing after you read the relevant documentation?
Don't worry, I got it now. (Ah Perl...how you warped my mind...)

-- Theerasak
Oct 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Balaji | last post: by
9 posts views Thread by k.retheesh | last post: by
3 posts views Thread by bbawa1 | last post: by
12 posts views Thread by Petronius | last post: by
5 posts views Thread by Julius | last post: by
reply views Thread by Chris Rebert | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.