sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #15899
Re: [Question #221025]: How to import all files from a folder
Question #221025 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/221025
Status: Open => Answered
RaiMan proposed the following answer:
Sorry, not Python-like currently (as from sikuli import * works)
But this short hack helps to only have one place to maintain the list of
modules:
--- say we have the following scripts all in one folder
sub.sikuli
sub1.sikuli
sub2.sikuli
...
--- then in sub.sikuli (or an extra subAll.sikuli) enter the following
# in sub.sikuli second after from sikuli import *
imports = "import sub1;import sub2;import sub3;...."
# an extra subAll.sikuli
from sikuli import *
imports = "import sub;import sub1;import sub2;import sub3;...."
--- in the script, that wants to import:
# no subAll.sikuli
import sub
exec(sub.imports)
# with a subAll.sikuli
import subAll
exec(subAll.imports)
The trick is, that exec() does all the import statements given by
imports in the current context, so that afterwards all module names are
known globally.
all "import xxxx" can be substituted by "from xxxx import *" as well.
It might even be possible, to construct the imports string at time of
import by inspecting the current folder with some strategy.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.