How to call a function/module in a driver script from another sikuli script?

Asked by Rohan Ganapathy

For eg:

I Have a file with name MyFile.sikuli

from sikuli.Sikuli import *

class NewUserFlow():
    def TutorialOne(self):
                       __________
                       __________
                       __________
   def TutorialTwo(self):
                       __________
                       __________
                       __________
   def TutorialThree(self):
                       __________
                       __________
                       __________
test = NewUserFlow()
test.TutorialOne()
test.TutorialTwo()
test.TutorialThree()

Now I have a driver file MyDriver.Sikuli and I want to call Only "TutorialTwo" from the MyFile.sikuli file and not the others.

I Tried:
from sikuli.Sikuli import *
import MyFile.sikuli
MyFile.TutorialTwo()

But its executing the entire MyFile.sikuli file, instead of just the TutorialTwo.

Is there a way to do this? :)

Thanks in Advance!

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
RaiMan (raimund-hocke) said :
#1

--- modules, that are imported ...
are processed, when imported the first time in a python session. This is mainly used, to process some initialization code.
This means, that every code, that runs, when you run the module standalone is processed, when it is imported.
This usually is blocked, by checking, whether the module is imported or runs as main.

In your case, you simply should delete or comment out your "test" code from MyFile.sikuli

# MyFile.sikuli
from sikuli import *

class NewUserFlow():
   def TutorialOne(self):
      pass
   def TutorialTwo(self):
      pass
   def TutorialThree(self):
      pass
"""
test = NewUserFlow()
test.TutorialOne()
test.TutorialTwo()
test.TutorialThree()
"""

the usage in your driver script:
# MyDriver.Sikuli
import MyFile.sikuli
flow = MyFile.NewUserFlow()
flow.TutorialTwo()

BTW:
- with Sikuli X:
from sikuli import *
- and it is only needed in imported modules

Can you help with this problem?

Provide an answer of your own, or ask Rohan Ganapathy for more information if necessary.

To post a message you must log in.