← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #252800]: changes from True to False

 

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

RaiMan proposed the following answer:
But this is a rather clumsy solution.

Since your config file already has key/value pairs, just read the file
into a dictionary and use this during your script run:

config = {} # empty dictionary
configInput = open("C:\\Users\\Richi\\Desktop\\Instructions.txt") 
for line in configInput.readlines():
    (key, val) = line.strip().split("=")
    config[key.strip()] = val.strip()
configInput.close()

now you know your settings:
if config["configure.camera"] == "true":
    pass # do something that should be done in this case

if you "pythonize" your file like this:

configure.camera=True
configure.mobile=False
configure.radio=True

its even easier:

config = {} # empty dictionary
configInput = open("C:\\Users\\Richi\\Desktop\\Instructions.txt") 
for line in configInput.readlines():
    (key, val) = line.strip().split("=")
    config[key.strip()] = eval(val.strip()) # evaluates the given strings to the Python value True or False
configInput.close()

# now you know your settings:
if config["configure.camera"] : # now this is sufficient
    pass # do something that should be done in this case

Be aware:
- there is currently no error checking or exception handling, so if the Instructions file does not exactly contain what is expected, it might crash

allowed already now: leading and trailing whitespace for the line and the key and value:
so this is ok:
    configure.camera   = True

because of the use of strip()

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