sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #13279
Re: [Question #209132]: var across module
Question #209132 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/209132
Status: Open => Answered
RaiMan proposed the following answer:
Ok understood.
It is always good to know the whole story ;-)
Your problem is the following:
Each myModulex.py has its own global table, that is setup once at the first time (and only time in a main script run) it is imported.. This global table in each module does not contain the name EnableVerif, since there is no EnableVerif= in the module before it is used in the def()'s (where it is seen as global, because in the def there is no EnableVerif=, which would have it made local to the def).
The only (language defined) way to get a name from any other module into a modules global name table is to use
from sub import *
or this way (which avoids potential name clashing):
import sub
myGlobal = sub.someValue
supposing a sub.py containing
someValue = 0
So there is no way around, touching every myModulex.py
My suggestion:
-- in every myModulex.py add as first line
from myInit import *
-- in the main module you have to setup myInit.py before the imports of
myModulex
import sys
# check the parameter
if len(sys.argv) > 0 and sys.argv[1]=="foo": EnableVerif=1
else:EnableVerif=0
# setup myInit.py
fMod = open("myInit.py", "w")
fMod.write("EnableVerif=%d"%(EnableVerif))
fMod.close()
for i in range(n):
exec("import myModule%d"%(i))
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.