我正在嘗試使用subprocess.call調用列表時間。它似乎沒有工作。任何更好的方式來做到這一點。調用子進程中的列表項
import os, sys
import subprocess as sb
files_to_remove=['*.jpg','*.txt','*.gif']
for item in files_to_remove:
try:
**sb.call(['rm' %s]) %item** # not working
except:
print 'no %s files in directory' %item
子進程調用中雙星的用途是什麼? –
如果你沒有空白,那麼問題會更加明顯,你也不需要一個子進程來做到這一點 –
建議你看看[這個問題和答案](http:// stackoverflow。 COM /問題/ 6703668 /刪除-肯定的 - 文件 - 使用的Python)。 – mshildt