How to use functions from the main script?

Asked by Vit on 2017-11-02

Hello! Sorry for my english.

I have 2 files in the same folder: main.sikuli and second.sikuli

# --- main.sikuli:
def test():

import second
from second import *

# --- second.sikuli:
from sikuli import *
def startSecondScript():
    import main
    from main import *
    y = test()

[error] script [ main ] stopped with error in line 7
[error] NameError ( global name 'test' is not defined )

How my second script can use functions from main script?

Thanks in advance!

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
aravind (aravind981) said : #1

Assuming that you want to call a function present in main.sikuli from second.sikuli , your could should be similar to this

 second.sikuli ::
import main
def startSecondScript():
    y = main.test()

main.sikuli ::
from sikuli import *
def test():

Please read the relevant answer in the below link

Vit (polet) said : #2

Thanks for your answer! Unfortunately, this does not work (the same error).

RaiMan (raimund-hocke) said : #3

I think this way it makes more sense:

Assuming that you want to call a function present in sub.sikuli from main.sikuli , your solution could be similar to this

sub.sikuli ::
from sikuli import * # needed in imported scripts
def doSomething():
    return(123) # what should be done in main.test

main.sikuli ::
import sub
def test():
test() # should print 123

take care that main.sikuli and sub.sikuli are in the same folder

Can you help with this problem?

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

To post a message you must log in.