← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #230996]: load config file without absolute path

 

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

    Status: Open => Needs information

RaiMan requested more information:
at 1: Since Sikuli IDE uses Jython/Python to run the scripts, the rules of Python apply for finding files that do not have an absolute path: the current working directory. this prints its current setting: import os; print os.getcwd()
Files with a relative path are searched relative to this working folder.
So currently there is no Sikuli specific setting, that allows to put files somewhere and open them without having an relative path

An easy option for script specific files (stored in the folder my-script.sikuli):
import os
scriptDir = getBundlePath()
f = open(os.path.join(scriptDir, "options.txt")
print readlines()
f.close()

for all other situations you have to specify an absolute path to open non-Sikuli files:
import os
scriptDir = r"c:\myStuff"
f = open(os.path.join(scriptDir, "options.txt")
print readlines()
f.close()

To define your own central place, that can easily be accessed by all scripts, set an environment variable to this central folder:
MYSTUFF=c:\myStuff

in your scripts you can use:
import os
scriptDir = os.environ["MYSTUFF"]
f = open(os.path.join(scriptDir, "options.txt")
print readlines()
f.close()

I have now on the request list: Want to open a file from a Sikuli known
place, by only specifying the filename.

at 2: you say ...
... It seems that Sikuli only loads the config file once after IDE starts

How do you manage, to tell Sikuli to "load the config file"?

Are we talking about import or execFile()?

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