← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #181852]: if statements inside for loop

 

Question #181852 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/181852

RaiMan proposed the following answer:
@ KRP
I got you zipped script and had a look at it.

I have rewritten parts of it and solved your loop issue. I have sent it
back to you.

Your coding generally works, but does not allow to nest any execution
below level 0

--- you code like that

if <some-condition>: (expression, expression, expression, expression, ...., expression)
elif <some-condition>: (expression, expression, expression, expression, ...., expression)
else (expression, expression, expression, expression, ...., expression)

This is syntactically ok. But it is a wast of resources: each expression
is evaluated from left to right and finally stored in an anonymous list
(tuple), that is not referenced again. And you cannot nest additional
if/while/for constructs, because these need to be statements.

--- normal Python scripting

if <some-condition>: 
    statement
    statement
    statement
elif <some-condition>: 
    statement
    statement
    statement
else: 
    statement
    statement
    statement

where each statement can be any valid i/while/else construct:

if <some-condition>: 
    statement
    if <some-condition>:
        statement
    else:
        statement
    statement
elif <some-condition>: 
    statement
    statement
    statement
else: 
    statement
    statement
    statement

The only tricky thing is indentation, which tells Python which
statements belong to a block of statements.

So to solve your issue see comment #1 of Mikeldi above, which is fully
correct based on the code snippet you gave in your question (I know,
that your real script looks different):

for entry in myListFixed:
    while exists(Pattern("1322634310829.png").similar(0.90).targetOffset(-2,1), 0):
        click("DDCCY.png")
        type(Key.DOWN)
        type("c", KEY_CTRL)
        click("img-1.png")
        exists("Coumry.png")
        doubleClick("Coumry-1.png")
        type("v", KEY_CTRL)
        if exists("Gen-1.png"):
            click("GenP.png")
            click("OpenPage-2.png")
            click("Administrato.png")

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.