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)
Pregunta
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
Solución
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)
Otros consejos
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 "