Question

I'm trying to run Zenity in a python script, to display a variable.

nmaj = 10
cmd = ["zenity" "--question" "--text='Are you " + str(nmaj) + "years old ?'"]
subprocess.call(cmd, shell=True)

Can I put a string in the command? How? Thanks

Was it helpful?

Solution

You can try using format and putting '' outer than "":

nmaj = 10
cmd = 'zenity --question --text="Are you {} years old ?"'.format(nmaj)
subprocess.call(cmd, shell=True)

OTHER TIPS

You miss comma(,)s between command line arguments:

cmd = ["zenity", "--question", "--text='Are you " + str(nmaj) + "years old ?'"]

Otherwise the string literals are concatenated into a string (See String literal concatenation):

>>> "zenity" "--question" "--text='Are you "
"zenity--question--text='Are you "
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top