sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #27696
Re: [Question #252629]: for loop/if elif statement not working correctly
Question #252629 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/252629
Jonas Maurer posted a new comment:
This is for Eugene: "try, except" is meant for exception handling. Not
for use in expected situations. Reason being it generates a ton of ugly
and slow code on C level. Never ever use exceptions to mimic if-else
behaviour.
For Glenna:
I removed a few lines of code that were redundant. Redundancy lowers robustness of your code and makes it more error prone, perhaps that is already enough of a solution.
instead of searching for caption three times per iteration, search once, and save the result in a match object.
then test wheter the match is valid,
if it is then use click on the match object instead of searching the very same picture again.
if it isn't there is no need to check if it is invalid, (that is already implied by the laws of binary fields)
check if there isn't a better way than clicking delete for Idon'tknowhowmanytimes.
pushing a button for "a lot of times" is usually a common source for errors, glitches (and inefficiency too).
for idx in range(5,106):
match = exists("caption.png"):
if match :
click(m)
type(Key.F2)
type("a", KeyModifier.CTRL)
type("c", KeyModifier.CTRL)
click("CLICKBOX-4.PNG")
click("BOX2-4.PNG")
type("a", KeyModifier.CTRL)
type(Key.DELETE)
type("v", KeyModifier.CTRL)
type(str(idx))
type(Key.HOME)
for c in range(25):
type(Key.DELETE)
click("1406907972716.png")
type(Key.PAGE_DOWN)
print idx
else:
click("1406907972716.png")
type(Key.PAGE_DOWN)
print "skip" + str(idx)
you can reduce the scan time of exist to 0 seconds like Eugene
mentioned; use exists("caption.png",0)
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.