How compare text from a region and integer

Asked by Dude

r = Region(242,340,203,157)
m =r.text()

n= 73

if m==n:
       print "exact match"
else:
       print "found something else"

In my code am trying to extract text from a particular region, it giving me the correct value
Now i need to compare that text with an integer , to perform some action

While am running this script , it gave me 73 value for m from selected region, but when i compare it , it fails and "found something else' is displayed. Whats wrong in my code.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

if you do it this way, either n must be a string or m must be a number.

1. both as string:

n= "73"
if m==n:
       print "exact match"
else:
       print "found something else"

2. both as number:

m =int(r.text())
n= 73
if m==n:
       print "exact match"
else:
       print "found something else"

comment on 1:
this might still fail, since m might contain characters that are not visible when printed.
so you might use:
if m.count(n) > 0:

this looks for the string n in m.

comment on 2:
this might fail, if m cannot be converted to an integer, because the string not only contains digits.
You might use a regex, to get the number

import re
m = r.text()
re.match(".*(\d*?)", m)
mn = int(re.group(1)) if re.group(1) else Null
if mn and mn == n:

Revision history for this message
Dude (dhurga-devi) said :
#2

Hi,

Thanks a lot , solution 2 works for me

Revision history for this message
Dude (dhurga-devi) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Q17 (squery) said :
#4

Hi,

I have tried the following code to verify values in two different applications but it does not seem to work and the message log only printing 'Value does not match'. Could you kindly point out where am I doing it wrong? Thanks

In my excel file column A I have list of values like 1, 2, 3, 4

var = sheet.col_values(0) #this part is working I have tried with print var

var1 = Region() # this is the other application
var2 = var1.text() # the value here is 1

# below I want to check every value in column A and if there is match then print message accordingly
i = 0
for rows in sheet.col(3):
 if var2 == var[p]:
    print 'Value match'
 else:
    print 'Value does not match'

Revision history for this message
Q17 (squery) said :
#5

Just to mention the OCR is switched on.