← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #144555]: How can I import Sikuli scripts to re-use them?

 

Question #144555 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/144555

    Status: Open => Answered

RaiMan proposed the following answer:
--1. Be aware: the parameter self will only be filled automatically, if
it is part of a test-suite

#### Library script ####
from sikuli.Sikuli import *
def setPermission (self):
 print ("hola")

--2. methods/functions in Python have always be called as function(). If
you leave out the (), it does not give an error, it just returns a
method obeject (try for fun: print setPermission).

your function call has to be:
setPermission(None)
since your funtion requires a parameter, that in your case is not used.
 
####### Test Script ############
myScriptPath = "C:\\scripts\\sanity_test\\"
if not myScriptPath in sys.path: sys.path.append(myScriptPath)
import Project_Sanity_Test_library
from Project_Sanity_Test_library import *

setPermission(None)
#############################

So you could mock up your def like this:
def setPermission (self):
 if not self:
  print "no test-suite. running as main"
 print ("hola from setPermission")

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.