← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #667197]: how can i check if value is integer or string? Err in conversion

 

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

Description changed to:
Hi there,

after correct OCR from images, removing any dots commas and letters if
recognised by mistake, than convert string to int and tried to compare
with variable - digits. Im looking to use function to show wheter value
is string or int or float or whatever it is to check if my conversions
was successful or not. This is my simple code.

---
# set variables to compare
vpmin = int("40000")
vpmax = int("349999")

if exists("1521886809839.png"):
        vpvalue=find("1521886809839.png").text()
# replace any unnessery trash as a string
        vpvalue = vpvalue.replace("X", "")  # 1
        vpvalue = vpvalue.replace(".", "")  # 2
        vpvalue = vpvalue.replace(",", "")  # i know i could do it with regex or something ;)
        converted_vpvalue = int(vpvalue)

# compare values
if converted_vpvalue >= vpmin and converted_vpvalue <= vpmax:
        do some actin...
---

Got error "TypeError: cannot concatenate 'str' and 'int' objects" but
thought that int() converted all correctly, and dont know what is not
converted - variables at start or converted_vpvalue

when debuggin variables before some actions i got
clean OCR'ed value "X259.240"
after sting trash replace "259240"
and when converted was same as replaced value

OCR - im getting text via find().text() coz i think that in my situation
is faster than region().text() and got less script termination... but
not certain and im using if exists to get OCR becouse sometimes lasts
more than 3 sec to render action with correct images - avoiding error in
script, works great.

1 OCR gives me string coz value on img is with two crossed swords at the begining which is recognized as "X"  ;)
2 removing X, dot or comma before conversion to int coz i think that if value is 350.200 its divide it to two diffrent numbers when tried to compare in if statement

Weird is that when variables vpmin and vpmax was set like vpmax="349999"
w/o int() all was workin ok, probably script was comparing both values
as string but was not accurate and sometimes didn't pass through if
statement when matched (but rather was correct and all was workin)

tried few stuff from forum like
https://answers.launchpad.net/sikuli/+question/123516 but nothin helped

im not a regular programmer or something but after few days spent in this forum lurking for my problems i had at the beginning of my scripting and reading sikuli doc i have no problems with creating automation of my stuff beyond this conversion and comparision two values.
Is something wrong with conversion or exists function to check wheter type the value is.. i know i could leave conversion and still check two strings like before, but you know... more precise means always better ;)

Thank You in advance,
Adrian

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.