如下所示:
def usage(): print(' * usage:') print(' * -c [val] : exporter_conf filepath, default importer_conf.') print(' * -h : print this.') print(' * -z : 不需要確認參數,直接執行')do_not_confirm = Falseconf = ''#c: [c+冒號表示-c 后面有參數,hz表示-h,-z后面沒參數,如果此時在-h 100加上參數,那么這個100的值是獲取不到的] opts, args = getopt.getopt(sys.argv[1:], 'c:hz') for op, value in opts: value = value.replace('/'', '').replace('/"', '') if op == '-c': conf = value elif op == '-h': usage() sys.exit() elif op == '-z': do_not_confirm = True以上這篇python 執行文件時額外參數獲取的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答