我試圖用鉛在Python中執行以下命令傳遞$:Python的鉛:在cmd參數
sort -u -f -t$'\t' -k1,1 file1 > file2
傳遞-t$'\t'
說法不過,我有問題。這裏是我的代碼:
from plumbum.cmd import sort
separator = r"-t$'\t'"
print separator
cmd = (sort["-u", "-f", separator, "-k1,1", "file1"]) > "file2"
print cmd
print cmd()
後print separator
和print cmd()
執行,我可以看到問題的時候了:
-t$'\t'
/usr/bin/sort -u -f "-t\$'\\t'" -k1,1 file1 > file2
- 的說法是雙引號括起來。
- 插入$和$ t之前的額外\。
我應該如何將這個論點傳遞給鉛?
你試過這個:'separator =「-t $'\ t'」'?你可以解釋這是一種將TAB作爲字段分隔符的方法。順便說一句,你知道這是非常非常容易做到使用python只是嗎? –
@ Jean-FrançoisFabre這個參數看起來像這個命令裏面的內容:「-t \ $'\\ t'」(帶雙引號)。 – SteveB
然後,應該工作,嘗試它。 –