Pythonでファイルの存在確認をするには
#!/usr/bin/env python import os if os.path.exists("/tmp/hoge.png") : print "Exists" else : print "Not Exists" print "end"
os を使う。
bashの場合
if [ -f /tmp/hoge.png ]; then echo "Exists" fi
python でスクリプトを作って引数を取りたいときに引数の個数を取得するには。
import sys if len(sys.argv) < 3 : print "引数が足りません" exit() print sys.argv
実際に実行してみた結果
takuya@rena:~/Desktop$ python test.py aaa 引数が足りません takuya@rena:~/Desktop$ python test.py aaa bbb ['test.py', 'aaa', 'bbb'] takuya@rena:~/Desktop$ python test.py aaa bbb ccc ['test.py', 'aaa', 'bbb', 'ccc']
例に漏れずARGV[0] は自分自身のファイル名を示すことになります。
if [ $# -ge 2 ]; then echo "引数が足りません" exit() fi