Python getopt() 的使用
import getopt
import sys
try: opts, args = getopt.getopt(sys.argv[1:], "ho:", ["help", "output="]) except getopt.GetoptError: # print help information and exit
try: opts, args = getopt.getopt(sys.argv[1:], " 短格式 ", [ 長格式 ])
上面的例子。
短格式: -h / -o 後有一個參數
長格式:--help / --output= 後有一個參數
如果輸入的令命列為 xxx.py -h -o file --help --output=out file1 file2
sys.arg[0] = “xxx.py”
opts = [('-h', ''), ('-o', 'file'), ('--help', ''), ('--output', 'out')]
args = ['file1', 'file2']













