← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #202298]: Variable value from the imported file gets initialized every time

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Variables defined in a module are always local to that module.
So in the same way as the function, you have to qualify with the module or use from xyz import *, which makes all names available in the global namespace (no module. needed).

-- version 1:
# main
import sub
reload(sub) #comment
sub.a = "from main"
sub.fn()

# sub
a = "from sub"
def fn():
    print a

-- version 2
# main
import * #comment
reload(sub) #comment
from sub import *
a = "from main"
fn()

The statements marked with #comment are only needed when running in the
IDE, to always get a fresh copy of module on rerun (see
http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-
reuse-code-and-images -> Some comments for readers not familiar with
Python import)

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