how to call python script in SikuliX and viceversa?

Asked by vinod dangare

Hi RaiMan,

I have defined one function in python script.

Function.py is the python script file name.

def printme( str ):
   print (str)
   return

I have call this printme(str) function in SikuliX IDE as follows:

import sys
mySikuliPath = "C:\Users\infodba\Desktop\SikuliX\Function.py"
if not mySikuliPath in sys.path: sys.path.append(mySikuliPath)
import Function
printme ("I am first call to user defined function")

I have kept Function.py file in same SikuliX IDE folder where my SikuliX script is there.

When I am trying to execute Sikulix Script I am getting error as follows:

[error] script [ temp ] stopped with error in line 5
[error] NameError ( name 'printme' is not defined )

Please help me on this and let me know if you have sample code or any document link avialable.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
danman (danman) said :
#1

Maybe line 5 should be:

Function.printme("I am first call to user defined function")

Revision history for this message
RaiMan (raimund-hocke) said :
#2

With SikuliX the recommended way is to only use .sikuli folders containing the .py file (same name), even if no images are used.

This allows to get the most comfortable approach:
see http://sikulix-2014.readthedocs.io/en/latest/scripting.html#importing-other-sikuli-scripts-reuse-code-and-images

# content of Function.sikuli
def printme( str ):
   print (str)
   return

# content of main.sikuli
import Function
Function.printme("I am first call to user defined function") # as danman mentioned in comment #1

or
from Function import *
printme("I am first call to user defined function")

the latter needs a proper naming convention to avoid conflicts

Can you help with this problem?

Provide an answer of your own, or ask vinod dangare for more information if necessary.

To post a message you must log in.