On Sep 5, 11:17 am, James Stroud <[EMAIL PROTECTED]> wrote: > bambam wrote: > > I have about 30 pages (10 * 3 pages each) of code like this > > (following). Can anyone suggest a more compact way to > > code the exception handling? If there is an exception, I need > > to continue the loop, and continue the list. > > > Steve. > > > ----------------------------------- > > for dev in devs > > try: > > dev.read1() > > except > > print exception > > remove dev from devs > > > for dev in devs > > try: > > dev.read2() > > [etc.] > > My keen sense of pattern recognition tells me that all of your read's > follow the same naming pattern--or was that just an accidental naming > coincidence on your part for the sake of example? > > for i in xrange(number_of_reads): > for dev in devs: > try: > _reader = getattr(dev, 'read%d' % i) > _reader() > except Exception, e: > print e > devs.remove(dev)
I see in many of the solutions suggested above, the devs sequence/ iterator is being modified while iterating. I know it is not defined for interation over dictionary keys. Are they defined for other collections like lists? Karthik > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list