How To Send Python Variable To Bash Variable?
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 i
Solution 1:
I suppose you can use os.system
, but better might be subprocess
:
import subprocess
subprocess.call(['say',x])
Solution 2:
you are passing astring you can use value of x like
sytem('say {0}'.format(x))
When passing strings you can use string formatting. As you realized you need to get the value of x in the string not the variable x http://docs.python.org/library/string.html#format-examples
Solution 3:
You can use format:
system('say {}'.format(x))
Solution 4:
use string formatting:
In [9]: x="ls -ld"
In [10]: os.system("{0}".format(x))
drwxr-xr-x 41 monty monty 40962012-10-1022:46 .
Out[10]: 0
Post a Comment for "How To Send Python Variable To Bash Variable?"