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

熱線電話:13121318867

登錄
首頁精彩閱讀Python中常見的異??偨Y(jié)
Python中常見的異??偨Y(jié)
2018-04-28
收藏

Python中常見的異常總結(jié)

當(dāng)Python檢測到一個錯誤時,解釋器就會指出當(dāng)前流已經(jīng)無法繼續(xù)執(zhí)行下去,這時候就出現(xiàn)了異常。

一、異常錯誤
   a、語法錯誤

    錯誤一:
    if
    錯誤二:
    def  text:
          pass
    錯誤三:
     print(sjds

    b、邏輯錯誤
    
#用戶輸入不完整(比如輸入為空)或者輸入非法(輸入不是數(shù)字)
 
num=input('>>:')
   int(num)
 
#無法計算
rest=1/0
rest2=1+str
 二、什么是異常
    a、程序運行時發(fā)生的錯誤的信號
    b、異常種類:
    在Python中不同的的異??梢杂貌煌念愋蛥^(qū)標(biāo)識,不同的類對象標(biāo)識不同的異常,一個異常標(biāo)識一個錯誤

    AttributeError 試圖訪問一個對象沒有的樹形,比如foo.x,但是foo沒有屬性x
    IOError 輸入/輸出異常;基本上是無法打開文件
    ImportError 無法引入模塊或包;基本上是路徑問題或名稱錯誤
    IndentationError 語法錯誤(的子類) ;代碼沒有正確對齊
    IndexError 下標(biāo)索引超出序列邊界,比如當(dāng)x只有三個元素,卻試圖訪問x[5]
    KeyError 試圖訪問字典里不存在的鍵
    KeyboardInterrupt Ctrl+C被按下
    NameError 使用一個還未被賦予對象的變量
    SyntaxError Python代碼非法,代碼不能編譯(個人認為這是語法錯誤,寫錯了)
    TypeError 傳入對象類型與要求的不符合
    UnboundLocalError 試圖訪問一個還未被設(shè)置的局部變量,基本上是由于另有一個同名的全局變量,導(dǎo)致你以為正在訪問它
    ValueError 傳入一個調(diào)用者不期望的值,即使值的類型是正確的

   c、什么時候用異常處理:你能想到有異常,并且可能出現(xiàn)在這一塊代碼的異常有很多種,不能一一枚舉

   d、異常處理:

         首先須知,異常是由程序的錯誤引起的,語法上的錯誤跟異常處理無關(guān),必須在程序運行前就修正

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

若不方便掃碼,搜微信號: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(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務(wù)器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".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 = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+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); }