How to get a command to repeat about 10 times

Asked by arminius on 2017-06-20

"click("460450485686722.png")
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()"

What's an easy way to just click() * 10
I tried the above command, it just clicked once.

Mint 18.1 KDE

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2017-06-26
Last query:
2017-06-26
Last reply:
2017-06-22
Manfred Hampl (m-hampl) said : #1

Standard Python syntax
https://wiki.python.org/moin/ForLoop

for n in range(0, 10):
        click()

count = 1
while (count < 10):
 click("460450485686722.png")
 count = count + 1
print ("finish")

arminius (arminius75) said : #3

"count = 1
        while (count < 10):
        click(Pattern("58679475550934.png").targetOffset(-8,-8))
        count = count + 1"

returns "[error] SyntaxError ( "mismatched input 'click' expecting INDENT", )"

arminius (arminius75) said : #4

"for n in range(0, 10):
        click()"

returns "[error] SyntaxError ( "mismatched input 'click' expecting INDENT", )"

Best Manfred Hampl (m-hampl) said : #5

You seem to have misformatted the input.
Whitespace is significant in Python.
Python groups statements according to the amount of whitespace in front of it.

"count = 1
         while (count < 10):
         click(Pattern("58679475550934.png").targetOffset(-8,-8))
         count = count + 1"
is wrong, it probably has to be
"count = 1
while (count < 10):
         click(Pattern("58679475550934.png").targetOffset(-8,-8))
         count = count + 1"
denoting that the indented lines (click... and count=count+1) are inside the while loop.

Please check with python manuals.

arminius (arminius75) said : #6

"count = 1
while (count < 10):
         click(Pattern("58679475550934.png").targetOffset(-8,-8))
         count = count + 1"

returned [error] SyntaxError ( "mismatched input ')' expecting NEWLINE", )

Manfred Hampl (m-hampl) said : #7

It seems that you have an extra closing bracket somewhere.
Are you sure that the error is caused by one of the lines in your snippet and not by some other part of your code?

arminius (arminius75) said : #8

Thanks Manfred Hampl, that solved my question.