try/except in a loop

J. Mwebaze jmwebaze at gmail.com
Wed May 2 15:51:22 EDT 2012


I have multiple objects, where any of them can serve my purpose.. However
some objects might not have some dependencies. I can not tell before hand
if the all the dependencies exsit. What i want to is begin processing from
the 1st object, if no exception is raised, i am done.. if an exception is
raised, the next object is tried, etc  Something like

objs = [... ]
try:
  obj = objs[0]
  obj.make()
except Exception, e:
  try:
      obj = objs[1]
      obj.make()
  except Exception, e:
     try:
        obj = objs[2]
        obj.make()
     except Exception, e:
       continue

The problem is the length of the list of objs is variable... How can i do
this?



-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120502/f60d6288/attachment.html>


More information about the Python-list mailing list