[1.1.1] runScript: Error of 2nd arg can't be coerced to String[] --- parameters must be simple strings

Asked by lynn on 2018-01-22

I met below error when try to use sys.argv[] on sikuli IDE 1.1.1

I am try to parse below array to another script in IDE

Settings.DebugLogs=True
pt1=("25","225")
pt2=("25","235")
pt3=("127.5","25")
mylist=(pt1,pt2,pt3)
print mylist
runScript("D:/KT_Work/Sikuli/tempTest.sikuli",mylist)

and "D:/KT_Work/Sikuli/tempTest.sikuli" is as

myList=sys.argv[1]
print sys.argv[1]

but error display as

[error] Error caused by: Traceback (most recent call last): File "D:\KT_Work\Sikuli\5xx.sikuli\5xx.py", line 24, in <module> runScript("D:/KT_Work/Sikuli/tempTest.sikuli",pt1) File "D:\KT_Work\Sikuli1.1.1\NewSikuli\sikulix.jar\Lib\sikuli\Sikuli.py", line 559, in runScript TypeError: run(): 2nd arg can't be coerced to String[]

What is the error?

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-01-23
Last query:
2018-01-23
Last reply:
2018-01-23
RaiMan (raimund-hocke) said : #1

try:
mylist=[pt1,pt2,pt3]

lynn (wuwangxia) said : #2

Thanks for reply, just tried but still get the same error

The error is about Python / Jython not able to convert mylist to string automatically.
It looks like it wants to unpack tuple for the arguments.
You need to build the string(s) you want from mylist with your Python instructions.

Unfortunately I can't guess what the argument string you need.

Does "print mylist" output what you expect?

If so, you can try str(mylist) before runScript line.

lynn (wuwangxia) said : #4

Hi Roman
I want to parse a list of coordinators, that is why I do the experiment

"print mylist" could work successfully as

[('25', '225'), ('25', '235'), ('127.5', '25')]

Maybe I need to find another way to do it. Any suggestions?

lynn (wuwangxia) said : #5

And I change to main script as

Settings.DebugLogs=True
pt1=("25","225")
pt2=("25","235")
pt3=("127.5","25")
mylist=[pt1,pt2,pt3]
str(mylist)
print mylist
runScript("D:/KT_Work/Sikuli/tempTest.sikuli",mylist)

but still get the same error

[error] Error caused by: Traceback (most recent call last): File "D:\KT_Work\Sikuli\5xx.sikuli\5xx.py", line 25, in <module> runScript("D:/KT_Work/Sikuli/tempTest.sikuli",mylist) File "D:\KT_Work\Sikuli1.1.1\NewSikuli\sikulix.jar\Lib\sikuli\Sikuli.py", line 559, in runScript TypeError: run(): 2nd arg can't be coerced to String[]

lynn (wuwangxia) said : #6

At above result "print mylist" also works. Complete result is

[('25', '225'), ('25', '235'), ('127.5', '25')]
[error] script [ 5xx ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "D:\KT_Work\Sikuli\5xx.sikuli\5xx.py", line 25, in <module> runScript("D:/KT_Work/Sikuli/tempTest.sikuli",mylist) File "D:\KT_Work\Sikuli1.1.1\NewSikuli\sikulix.jar\Lib\sikuli\Sikuli.py", line 559, in runScript TypeError: run(): 2nd arg can't be coerced to String[]

Best RaiMan (raimund-hocke) said : #7

Uuups, sorry for the misleading of the discussion.

The problem is built-in by the one, who implemented runScript (guess who ;-)

The parameters given to runScript are internally just taken as is. Each parameter must be a string. Lists(arrays) are taken as is and not resolved into their parts.

so your
runScript("D:/KT_Work/Sikuli/tempTest.sikuli",mylist)

will never work with the current implementation.

You either have to say:
runScript("D:/KT_Work/Sikuli/tempTest.sikuli", pt1, pt2, pt3)

and ptx must be something like
""25, 225"

and you have to recover the list behavior in the target script using split(",").

or you use another parameter convention, that completely is based on strings.

And another option finally is:
parameters = "(%s, %s, %s)"%(pt1, pt2, pt3)

... and use
runScript("D:/KT_Work/Sikuli/tempTest.sikuli", parameters)

... and in the target script:
parameters = eval(sys.argv[1])

RaiMan (raimund-hocke) said : #8

... added a remark to the docs.

I make this a request bug, because your first approach makes sense.

lynn (wuwangxia) said : #9

Thanks RaiMan, that solved my question.

lynn (wuwangxia) said : #10

I see, thanks a lot.
I will try the suggestions you give :)