99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁(yè)精彩閱讀Python處理命令行參數(shù)模塊optpars用法實(shí)例分析
Python處理命令行參數(shù)模塊optpars用法實(shí)例分析
2018-07-19
收藏

Python處理命令行參數(shù)模塊optpars用法實(shí)例分析

本文實(shí)例講述了Python處理命令行參數(shù)模塊optpars用法。分享給大家供大家參考,具體如下:
optpars是python中用來(lái)處理命令行參數(shù)的模塊,可以自動(dòng)生成程序的幫助信息,功能強(qiáng)大,易于使用,可以方便的生成標(biāo)準(zhǔn)的,符合Unix/Posix 規(guī)范的命令行說(shuō)明。
使用 add_option() 來(lái)加入選項(xiàng),使用 parse_args() 來(lái)解析命令行。
add_option()中參數(shù)
第一個(gè)參數(shù)表示option的縮寫(xiě),以單個(gè)中劃線引導(dǎo),例如-f、-d,只能用單個(gè)字母,可以使用大寫(xiě);
第二個(gè)參數(shù)表示option的全拼,以兩個(gè)中劃線引導(dǎo),例如--file、--Opencv_version;
第一第二個(gè)參數(shù)可以單獨(dú)使用,也可以同時(shí)使用,但必須保證有其中一個(gè);
從第三個(gè)參數(shù)開(kāi)始是命名參數(shù),是可選參數(shù),常用的幾個(gè):
type=: 表示輸入命令行參數(shù)的值的類型,默認(rèn)為string,可以指定為string, int, choice, float,complex其中一種;
default=: 表示命令參數(shù)的默認(rèn)值;
metavar=: 顯示到幫助文檔中用來(lái)提示用戶輸入期望的命令參數(shù);
dest=:指定參數(shù)在options對(duì)象中成員的名稱,如果沒(méi)有指定dest參數(shù),將用命令行參數(shù)名來(lái)對(duì)options對(duì)象的值進(jìn)行存取。
help=:  顯示在幫助文檔中的信息;

解析命令行    
(options, args) = parse.parse_args()

或在main(argv)函數(shù)里:    
(options, args) = parser.parse_args(argv)

options,是一個(gè)對(duì)象(optpars.Values),保存有命令行參數(shù)值。通過(guò)命令行參數(shù)名,如 file,訪問(wèn)其對(duì)應(yīng)的值: options.file ;
args,是一個(gè)由 positional arguments 組成的列表;

optparse使用    
import sys
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-f','--file',type=str,default='./image',help='file path of images',dest='file_path')
parser.add_option('--weights','-w',type=str,default='./weights_saved',help="file location of the trained network weights")
parser.add_option('--iterations','-i',type=int,default=10000,help='iteration time of CRNN Net')
parser.add_option('--gpu','-g',type=int,default=0,help="gpu id")
def main(argv):
  (options, args) = parser.parse_args()
  (options, args) = parser.parse_args(argv)  # both OK
  print 'file path of images: ' + options.file_path
  print "file location of the trained network weights: " + options.weights
  print 'iteration time of CRNN Net: ' + str(options.iterations)
  print 'gpu id: ' + str(options.gpu)
if __name__ == '__main__':
 main(sys.argv)

查看幫助文檔:    
python test.py -h

顯示:

    Usage: test.py [options]
    Options:
      -h, --help            show this help message and exit
      -f FILE_PATH, --file=FILE_PATH
                            file path of images
      -w WEIGHTS, --weights=WEIGHTS
                            file location of the trained network weights
      -i ITERATIONS, --iterations=ITERATIONS
                            iteration time of CRNN Net
      -g GPU, --gpu=GPU     gpu id

輸入命令行參數(shù):    
python test.py -f ../tensorflow/train_image -w ../tensorflow/weights -i 5000 -g 2

輸出:

    file path of images:  ../tensorflow/train_image
    file location of the trained network weights:  ../tensorflow/weights
    iteration time of CRNN Net:  5000
    gpu id:  2

數(shù)據(jù)分析咨詢請(qǐng)掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測(cè)極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說(shuō)明請(qǐng)參見(jiàn):http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }