By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

Difference between unindexable and unsubscriptable

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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.