How robust is Python ?

Thomas Wouters thomas at xs4all.net
Fri Jan 12 20:32:53 EST 2001


On Sat, Jan 13, 2001 at 11:36:45AM +0200, Moshe Zadka wrote:
> On Fri, 12 Jan 2001, "Sandipan Gangopadhyay" <sandipan at vsnl.com> wrote:

> > If I try a catch-all except, continue hits except on the outer level rather
> > than while. Probably the reason that it results in syntax error.
> > 
> > while binAliveMarker:
> >   try:
> >     if binWannaStartAgainLater:
> >       time.sleep(1)
> >       continue
> >     work code ...
> >   except:
> >     pass
> > 
> > Any suggestions to make it work with continue (or an alternative) ? Apart
> > from removing continue completely by making the work code inside an else ?

> I'm afraid that's your only alternative, unless you can afford to wait
> for Python 2.1 or switch to JPython, both of which support continue
> inside a try clause.

Moshe is forgetting:

ContinueMePleaseError = "please continue" # or a class if you prefer that
while binAliveMarker:
  try:
    if binWannaStartAgainLater:
      time.sleep(1)
      raise ContinueMePleaseError
    work code ...
  except ContinueMePleaseError:
    continue
  except:
    pass

which is the usual way of working around it (other than reworking your code,
that is.)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list