1
我的python代碼在bash腳本中調用,並且python腳本還需要bash循環中的輸入參數。但我不確定最好的方法來做到這一點。這裏是我的嘗試:調用python腳本,需要從bash中輸入循環
慶典代碼:
cat filelList.txt | while read i;#file1List.txt stores file names
do
python script.py $i > $i.txt
done
蟒蛇位的是我不知道的:
file = sys.argv[0] # not sure about this
in = open(file)
for line in iter(in): # not sure about this
do something.......
有誰知道寫這些蟒蛇3行的最好方法?謝謝
'in'是一個保留字,你不能在變量名中使用它。 – 2014-11-20 21:35:49
查看此答案http://stackoverflow.com/a/1009879/2676531及其第一條評論。 – Celeo 2014-11-20 21:37:15
sys.argv [0]不是第一個參數,而是您正在運行的腳本的名稱。 – igon 2014-11-20 21:39:29