Re: try/except in a loop

2012-05-03 Thread Jean-Michel Pichavant
Peter Otten wrote: Jean-Michel Pichavant wrote: Chris Kaynor wrote: On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: 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

Re: try/except in a loop

2012-05-03 Thread Peter Otten
Jean-Michel Pichavant wrote: > Chris Kaynor wrote: >> On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: >> >>> 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 dependencie

Re: try/except in a loop

2012-05-03 Thread Jean-Michel Pichavant
Chris Kaynor wrote: On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: 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 fro

RE: try/except in a loop

2012-05-02 Thread Prasad, Ramit
> >> for obj in objs: > >> try: > >> obj.make() > >> except Exception: > >> continue > >> else: > >> break > >> else: > >> raise RuntimeError('No object worked') > > > > > > I think you misunderstand the else clauses. > > > for obj in [ 1,2,3,4 ]: > > ..

Re: try/except in a loop

2012-05-02 Thread Chris Kaynor
On Wed, May 2, 2012 at 1:12 PM, Prasad, Ramit wrote: >> > 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 >

RE: try/except in a loop

2012-05-02 Thread Prasad, Ramit
> > 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..

Re: try/except in a loop

2012-05-02 Thread Andrew Berg
Forgot to add that all this is covered in the tutorial in the official docs: http://docs.python.org/tutorial/controlflow.html#for-statements -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 -- http://mail.python.org/mailman/listinfo/python-list

Re: try/except in a loop

2012-05-02 Thread Andrew Berg
Why wouldn't a for loop work? If something works, you can break out, otherwise continue. working_obj = None for obj in iterable: try: obj.do_something() working_obj = obj break except: continue -- CPython 3.3.0a3 | W

Re: try/except in a loop

2012-05-02 Thread Chris Kaynor
On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: > 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,

try/except in a loop

2012-05-02 Thread J. Mwebaze
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 ra