← Back to team overview

sikuli-driver team mailing list archive

[Bug 1758592] [NEW] how can i check if value is integer or string? Err in conversion

 

Public bug reported:

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. Got TypeError: cannot concatenate 'str' and
'int' objects. 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

** Affects: sikuli
     Importance: Undecided
         Status: Invalid

** Description changed:

  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. Got TypeError: cannot concatenate 'str' and
  'int' objects. 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")
  
- # OCR text via find().text() i think that in my situation is faster than
- region().text() but not certain
- 
- --- 
- if exists("1521886809839.png"): 
-         vpvalue=find("1521886809839.png").text()  # OCR gives me string coz value on img is with two crossed swords at the begining which is recognized as "X"
+ 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)
+         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:
  ---
  
  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
  
- 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 like i said crossed swords are recognised as "X"  ;)
- 2 removing 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) 
+ OCR text via find().text() i think that in my situation is faster than region().text() 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
  
- when debuggin variables before some actions i got 
+ 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)
+ 
+ when debuggin variables before some actions i got
  clean OCR'ed value "X259.240"
  after replace "259240"
  and when converted was same as replaced value
  
  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 bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1758592

Title:
  how can i check if value is integer or string? Err in conversion

Status in Sikuli:
  Invalid

Bug description:
  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. Got TypeError: cannot concatenate 'str' and
  'int' objects. 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

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1758592/+subscriptions


Follow ups