list.index

delphiro delphiro at zonnet.nl
Fri Jun 6 09:49:58 EDT 2003


First of all many, many thanks to the creators / maintainers of Python.

Since my discovery of this holy grail I have a development time for platform indepandent software which is almost identical to what is possible with Delphi for Windows. It is realy a great language and easily learned with my C / C++ and mostly Object Pascal experience. THANKS!
 
Now to the question...

is this the easiest way to check for the existance of an item in a list?
it looks a bit weird to check a for a listitem by using a try..except block

(code background; if the item is found the colour should change else the colour that was already given is ok)
[mycode]
try:
  x = self.selected_points.index( self.pointmarker )
  colour = DEFAULT_SELECTED_POINT_COLOUR
except ValueError:
  pass
[/mycode]

Thanks in advance,
Rob






More information about the Python-list mailing list