如何将 Python 变量发送到 bash 变量? [英] How to send Python variable to bash variable?
本文介绍了如何将 Python 变量发送到 bash 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Python 从列表中选择一个变量,然后使用 bash 命令大声朗读.现在我有这样的事情
I am trying to use Python to select a variable from a list, then speak it outloud using the bash command. Right now I have something like this
foo = ["a","b","c","d"]
from random import choice
x = choice(foo)
foo.remove(x)
from os import system
system('say x')
这表示x",我需要它来表示 x
变量的值.
This says "x", what I need is for it to say the value of the x
variable.
推荐答案
我想你可以使用 os.system
,但最好使用 subprocess
:
I suppose you can use os.system
, but better might be subprocess
:
import subprocess
subprocess.call(['say',x])
这篇关于如何将 Python 变量发送到 bash 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文