changing the List's behaviour?
Ben Finney
bignose-hates-spam at and-benfinney-does-too.id.au
Sun Jul 27 17:17:10 EDT 2003
On Sun, 27 Jul 2003 22:41:43 +0200, meinrad recheis wrote:
> i am very annoyed by the List's index out of bouds exception
> it forces me to complicate my code by adding length checking
No, it forces you to ensure your code doesn't try to access a
non-existent list element.
Or, it forces you to catch the exception and deal with it.
> i want to change the List so that it returns None if the index for
> accesssing list elements is out of bound.
This would prevent you from distinguishing between "the index was out of
range" and "the element at that index is the None object".
> i am not very experienced in python, so i ask you for suggestions.
Take a good look at the code that is accessing non-existent index
values. Why is it doing so? Do you really want a list (ordered
collection, with a fixed set of keys) or are there cases where you want
a dict (unordered collection, arbitrary set of keys)?
--
\ "I know you believe you understood what you think I said, but I |
`\ am not sure you realize that what you heard is not what I |
_o__) meant." -- Robert J. McCloskey |
Ben Finney <http://bignose.squidly.org/>
More information about the Python-list
mailing list