read location from file for dragDrop

Asked by thunderhill

I am trying to read coordinates of "Location" from file for dragDrop
Here the snippet

f = open("C\Test.txt")
for line in f.readlines():
    #print line
    dragDrop(Location(line),Location(200,200)
f.close()

The Text.txt contains
560,460
 The error is
[error] TypeError ... 1st arg can't be coerced to java awtPoint,org.sikuli.script.Location)

I am trying to automate multiple icons to be dragged and dropped in to a box whose Locations are stored in a Test.txt file
How to read from a file in a for loop for dragDrop Location?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Location expects 2 parameters being numbers.
The given string in variable line from your point of view looks like that, but cannot be converted by Python.

so this is one option you have (IMHO the easiest one):

f = open("C\Test.txt")
for line in f.readlines():
    exec("dragDrop(Location(" + line.strip() + "),Location(200,200)")
f.close()

we build a code line, that is correct Python and tell the interpreter to execute it.
the strip() eliminates leading/trailing whitespace like newline character.

Revision history for this message
thunderhill (thunderhill4) said :
#2

Thanks RaiMan, that solved my question.