sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #01596
Re: [Question #147486]: using try and except
Question #147486 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/147486
Status: Open => Answered
RaiMan proposed the following answer:
Looping: FAQ 1437
success = False
while not success:
try:
# code layer 1
success = True # this ends the loop
except:
try:
#code layer 2
continue # goes back to beginning of loop
except:
pass
except:
pass
if not success:
# here goes what you had before in your one except
break # you might wish to exit the loop here
# first statement after the loop
if not success:
popup("permanent error")
exit(1)
# we go on if successful
I guess you are asking this, because you want to catch FindFailed
exceptions. You should have a look at exists() which returns None in
case of FindFailed, so it can be used in ii/elif/while constructs:
while not exists(<some-image>):
# do something to make <some-image> come into existence
click(<some-image>) # in many cases you might use
# click(getLastMatch()) and avoid the same find() op
This usually makes the code more pretty against these ugly (even nested)
<try: except:>.
see: http://sikuli.org/docx/region.html#exception-findfailed
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.