我正在尝试在python脚本中运行Zenity以显示变量。
nmaj = 10
cmd = ["zenity" "--question" "--text='Are you " + str(nmaj) + "years old ?'"]
subprocess.call(cmd, shell=True)
我可以在命令中放置一个字符串吗?如何?谢谢
您可以尝试使用format
并将''
放在""
之外
nmaj = 10
cmd = 'zenity --question --text="Are you {} years old ?"'.format(nmaj)
subprocess.call(cmd, shell=True)
你在命令行参数之间错过了逗号( ,
)s:
cmd = ["zenity", "--question", "--text='Are you " + str(nmaj) + "years old ?'"]
否则,字符串文本将连接成字符串(请参阅字符串文本连接):
>>> "zenity" "--question" "--text='Are you "
"zenity--question--text='Are you "