← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #224366]: Reuse of code through import

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
The import concept of Python/Jython and hence Sikuli  is to have
modules, that have reusable portions of code in class() and def()
blocks. This means, when just saying import xyz, nothing would happen at
all. Then you call a def contained in xyz, that does something and so
on.

--- example

# main.sikuli
import sub
# .... some code
for x in range(100):
    sub.fct1()

# sub.sikuli
from sikuli import *
def fct1():
    print "hello from function 1"

So this is the general principle.

the approach you are trying to implement is better done with execfile(), which processes the given .py file once in the context of the calling script (all names are known in the file and vice versa).
The context of an imported module does not know anything about the defined name in the importing context!

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