← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #176034]: popup a variable within a string

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Should not make any problems, if favNUM is a string.

so this should work:

favNUM = input("Enter your favorite number")
popup("Your favorite number is " + favNUM + " because you're awesome")

since favNUM is a string, even if the user gives a number.

This does not work

favNUM = 42
popup("Your favorite number is " + favNUM + " because you're awesome")

since favNUM is a number now and is not automatically converted to a
string.

This works in that case:

favNUM = 42
popup("Your favorite number is " + str(favNUM) + " because you're awesome")

which will work too, if favNUM is a string already.

another example:

favNUM = None
while not favNUM:
    try: favNUM = int(input("Enter your favorite number"))
    except: continue
favNUM *= 42
popup("Your favorite number is now %d because you're awesome"%(favNUM))

this ensures, that the user enters a number and uses the % formatter to
produce the output.

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