← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #232183]: [How To] set variable value from OCR numerics

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
as a convention and saving some computing resources: all imports should
be at the beginning of your script

This would be a (recommended ;-) more generalized version of the
function and it returns a number:

def getValue( text ):
    m = re.match("[^0-9]*([0-9]*\.?[0-9]*)", text)
    try:
        return m.group(1) # returns the found value
    except:
        return -1 # returns -1 if any problems

usage:
balance = "USD30000.00" # as read by the previous region.text() function
bval = getValue(balance)
print "balance-text:", balance, "balance-value",  bval

your case even shorter:
balance = getValue( find().text() )
# now balance already is a numeric value

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.