← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #247820]: Problem calling functions in nested imports

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Ok, there is some magic behind that:
- if a valid import for a .sikuli is done, internally an entry is added to Sikuli's image path automatically, which leeds to that all images in imported .sikuli are found. But this has nothing to do with Python's import feature.
- So the fact, that images are found, need not mean, that the functions in this .sikuli are found as well, because this depends on the fact, wether the (module).function-name is known in the Python namespace at this moment.

so an 
import AllFunctions as af
makes all names defined in AllFunctions.py available in the current namespace, which can be accessed using af.xxx

So to get access to HandyFunction1() using af. HandyFunction1(),  AllFunctions.sikuli must contain a
from Function1 import *
which makes the name HandyFunction1 available in the namespace of af and you can use:
af.HandyFunction1()

if you only have 
import Function1 in AllFunctions.sikuli you must use:
af.Function1.HandyFunction1()
because now only the name Function1 is known in the context of af

or you use
import Function1 as F1 in AllFunctions.sikuli, then you can use:
af.F1.HandyFunction1()

Nevertheless: for every .sikuli, that is imported, there has to be the
containing folder in sys.path (exception: all .sikuli in the same folder
as the main script are found automatically)

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