Function in python file not running from sikuli

Asked by April L

I have written a sikuli script and then imported the python file. When I try to access a particular function (which is in the python file) from my sikuli script the required action is not performed. Sikuli is able to access the python file, if I run the sikuli script and there are any errors in the python file I can see them on sikuli logs. Just the function isn't running.
The files look similar to this

---Sikuli script---
import nameofpythonfile as lsyb
reload (lsyb)

     class firstclass(object):
         def __init__(self):
            self.abc=lsyb.nameofpythonfile("Path of file")
            #there are some other function in between

         def search(self,p)
             a=self.abc.func(p)

---python file---
def func(self,p):
   print("Hello")

#some other functions
if __name__=="__main__":

The above file prints Hello when I run it directly but not when I run it from sikuli.

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

I am not sure, what you are trying to achieve, but this works having main.sikuli and sub.py in the same folder:

# main.sikuli
sys.path.append(getParentFolder())
import sub as lsyb
reload (lsyb)

class firstclass(object):
  def __init__(self):
    self.abc=lsyb #.nameofpythonfile("Path of file")

  def search(self, p):
    a=self.abc.func(p)

cls = firstclass()
cls.search(lsyb)

# sub.py
def func(p):
  print("Hello" + str(p))

--- I do not understand, what this should do:
self.abc=lsyb.nameofpythonfile("Path of file")

--- a method def only needs self as first parameter if defined in a class

--- a class itself does nothing (just a dfinition) - to use it, it must be instantiated

Revision history for this message
April L (april96) said :
#2

Thanks RaiMan, that solved my question.