OCR number reading works but how to put in conditions?

Asked by MP

So I am really happy my script works and is reading numbers perfectly. I tested this with "print region.text()". But now I want that if he reads a "1" that he does action 1. I tried the following code but I get the following error:

[error] script [ test_OCR ] stopped with error in line 6 at column 10
[error] SyntaxError ( "mismatched input '=' expecting COLON", )

code:
======================
tr = TextOCR.start()
tr.setPSM(6)
r = Region(Region(1056,315,26,26))

if r.text() = "1":
        print "action 1"
else:
        print "nothing"
=====================

Cheers!

Question information

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

--- SyntaxError ( "mismatched input '=' expecting COLON", )

means you did something wrong according to the Python language rules:
comparison is ==

Revision history for this message
MP (jozzzzzz) said :
#2

Ah yes silly me, I am learning python and sikulix at the same time. It is going pretty well imo. :)

============================
tr = TextOCR.start()
tr.setPSM(6)
r = Region(1056,315,26,26)
OCRnumber = r.text()

print OCRnumber #just to check and compare the number with my own eyes

if OCRnumber == 1:
    print 1
else:
    print 2

===========

I always get 2 as a result. Does this mean the text() is not an integer? I dont understand why he doesnt print 1. The OCRnumber is the number 1

Revision history for this message
MP (jozzzzzz) said :
#3

My print result from the previous code in #2 is:

1

2

Revision history for this message
RaiMan (raimund-hocke) said :
#4

last silly question for today ;-) (it is evening now for me)

OCRnumber is a String

1 is Number

which are always unequal.

best solution:

if int(OCRnumber) == 1:

Revision history for this message
MP (jozzzzzz) said :
#5

I am such an idiot - _ - Yes you are right, I need a break. haha
Thank you for your patience. I am happy with my progress so far.