2013-12-08 43 views
0

從命令行其工作,但是當我包括在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! 
+1

嘗試: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

回答

2

你看那個東西在sed之一:

... | sed -e 's/%]//g' | ... 

更改該位,以這樣的:

... | sed -e 's/%%]//g' | ... 

這是你如何逃避串的%python

+0

從%%過後,我現在得到這個:'回覆amixer -c2 | grep「簡單調音臺控制'麥克風',0」-A 5 | grep「Mono:」| sed -e's/Capture/ /g'|尾-1 | awk'{print $ 2}'| sed -e's /%] // g'| sed -e's/\ [// g' sed:-e表達式#1,字符11:未終止的's'命令 grep:寫入錯誤:損壞的管道# – YumYumYum

+0

好的 - 謝謝,\\ n我需要 – YumYumYum

相關問題