0
我有一個Python腳本,將採取目錄中的每個文件,遍歷文件的內容併爲每個輸入文件創建一個輸出文件。此輸出文件可能有重複的條目,如果這樣做,我想只需要類似於UNIX命令的唯一值傳遞變量作爲字符串循環python
uniq -u input.file > output.file
雖然我可以用shell腳本來做到這一點,我想包括線蟒只會採取獨特的價值觀。我知道我能做到這一點:然而,當我試圖把這個循環,這樣就會使獨特的全我剛纔提出的文件
import os
os.system("uniq -u input.file > output.file")
:
for curfile in fs:
if curfile[-3:]=='out':
os.system("uniq -u %s > %s") % (str(curfile), str(curfile[:-4] + ".uniq")
我得到以下錯誤:
unsupported operand type(s) for %: 'int' and 'tuple'
我嘗試了一些語法來嘗試獲取變量識別,但無法在Web上找到類似的示例。任何建議將不勝感激。
您已經在'os.system(「uniq -u%s>%s」)中忘記了一個''')%(str(curfile),str(curfile [: - 4 ] +「.uniq」)'。 – Griffin
os.system的括號應該包含所有其餘的行,不應該嗎? – yosukesabai
doh! - 謝謝格里芬 – zach