changing a variable from true to false (sikuli)

Asked by Richi

Hello,

actually i have a question concerning a script using sikuli.

suppose i have an instruction which is saved in a txt.file named version.txt on my desktop.

the instruction saved in the version.txt file is: configure.camera=true

 i am looking for a function /code (that sikuli understands) in order that the instruction "configure.camera=true" can be changed

into "configure.camera=false" when i call that function.

thanx in advance

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Eugene S
Solved:
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Hi,

Actually you don't need to use Sikuli for that purpose.
As far as I understand you only need to find a line in file and rewrite it accordingly.

You can do that with clean Python, for example like that (WARNING, this will rewrite your file):

import fileinput

for line in fileinput.input(<fileName>, inplace = True):
     if appPattern in line: # If pattern found. In your case can be something like "configure.camera"
          print "configure.camera=<XXX>" #Write line to file with relevant status
     else:
          print line, #Just rewrites line

Hope that helps.

Cheers,
Eugene

Revision history for this message
Richi (ateeshr) said :
#2

Hello eugene ,

thank you for yr reply.

so if i understand your reasoning well, i just need to write the following lines in python:

can you correct the following lines below please?

import fileinput

 for line input.input(<version.txt>, inplace = True):
      if appPattern in line:

            print "configure.camera=<False>

         else:

               print line

Revision history for this message
Best Eugene S (shragovich) said :
#3

Hi Richi,

First of all, before you run any actual code, make sure you have your file backed up as this code WILL rewrite the file.

Generally you only want to find in file the line that includes "configure.camera" pattern and then write a new line (instead of the old one) with the relevant parameter. So it's one of the two:

configure.camera=True
or
configure.camera=False

For this specific scenario, the code looks like that:

import fileinput

def changeCameraParameter(status):
     for line input.input("C:\\Path\\...\\version.txt, inplace = True):
          if appPattern in line:
               print "configure.camera=status
         else:
               print line,

and then just run the function with relevant status ("True" or "False"):

changeCameraParameter("True")
or
changeCameraParameter("False")

Cheers,
Eugene

Revision history for this message
Richi (ateeshr) said :
#4

Thanks Eugene S, that solved my question.