Difference between unindexable and unsubscriptable
Ben Finney
bignose+hates-spam at benfinney.id.au
Wed Oct 11 01:38:01 EDT 2006
Jackson <jackson at hotmail.com> writes:
> 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
More information about the Python-list
mailing list