exceptions and items in a list

vincent wehren vincent at visualtrans.de
Mon Jan 10 16:10:38 EST 2005


rbt wrote:
> If I have a Python list that I'm iterating over and one of the objects 
> in the list raises an exception and I have code like this:
> 
> try:
>     do something to object in list
> except Exception:
>     pass
> 
> Does the code just skip the bad object and continue with the other 
> objects in the list, or does it stop?
> 
> Thanks

Fire up a shell and try:

 >>> seq = ["1", "2", "a", "4", "5", 6.0]
 >>> for elem in seq:
...     try:
...        print int(elem)
...     except ValueError:
...        pass


and see what happens...

--
Vincent Wehren



More information about the Python-list mailing list