從命令行其工作,但是當我包括在Python獲得這個Python的 - 如何解決這一行類型錯誤:沒有足夠的論據格式字符串
終端:
$ amixer -c2 | grep "Simple mixer control 'Mic',0" -A 5 | grep "Mono: " | sed -e 's/Capture /\n/g' | tail -1 | awk '{print $2}' | sed -e 's/%]//g' | sed -e 's/\[//g'
88
的Python:
tmp = "2"
a = """amixer -c%s | grep "Simple mixer control 'Mic',0" -A 5 | grep "Mono: " | sed -e 's/Capture /\n/g' | tail -1 | awk '{print $2}' | sed -e 's/%]//g' | sed -e 's/\[//g'""" % tmp
print "Reply " + a
a = os.popen(a).read()
print a
錯誤:
Running: /var/tmp/p/test.py (Sun Dec 8 20:58:07 2013)
Traceback (most recent call last):
File "/var/tmp/p/test.py", line 2, in <module>
a = """amixer -c%s | grep "Simple mixer control 'Mic',0" -A 5 | grep "Mono: " | sed -e 's/Capture /\n/g' | tail -1 | awk '{print $2}' | sed -e 's/%]//g' | sed -e 's/\[//g'""" % tmp
TypeError: not enough arguments for format string
Execution Successful!
嘗試:a = r('amixer -c2 | grep「簡單混音器控制'Mic',0」-A 5 | grep「單聲道:」| sed -e's/Capture/\ n/g'| tail -1 | awk'{print $ 2}'| sed -e's /%] // g'| sed -e's/\ [['g' 88')。不確定,但原始字符串應該做的伎倆! – Vivek