← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #237161]: how to pass a variable between multiple scripts

 

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

RaiMan proposed the following answer:
@ Aravind
principally ok, but for this case (see https://answers.launchpad.net/sikuli/+question/237151) a bit oversized ;-)

@Benjamin
2 possibilities:

-- 1.
use exit(n) in a script and give the return code as parameter to the next script run

-- 2.
you might use a file as intermediate storage

have a file in the same folder as the scripts (e.g. current_value.txt)

- to get the current value:
# supposing it only contains a number
import os
f = open(os.path.join(os.path.dirname(os.path.dirname(getBundlePath()), "current_value.txt"))
currentValue = int(f.readline().strip())
f.close()

now you have your current number in currentValue

comment:
os.path.dirname has to be applied twice to get the parent folder of the running script, because getBundlePath() returns a path with a trailing \

- to write a new value:
f = open(os.path.join(os.path.dirname(os.path.dirname(getBundlePath()), "current_value.txt"), "w")
print >> f, str(currentValue)
f.close()

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