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

熱線電話:13121318867

登錄
首頁精彩閱讀Python模塊學(xué)習(xí)filecmp文件比較
Python模塊學(xué)習(xí)filecmp文件比較
2018-08-27
收藏

Python模塊學(xué)習(xí)filecmp文件比較

filecmp模塊用于比較文件及文件夾的內(nèi)容,它是一個輕量級的工具,使用非常簡單。python標(biāo)準(zhǔn)庫還提供了difflib模塊用于比較文件的內(nèi)容。關(guān)于difflib模塊,且聽下回分解

filecmp定義了兩個函數(shù),用于方便地比較文件與文件夾:

filecmp.cmp(f1, f2[, shallow]):

比較兩個文件的內(nèi)容是否匹配。參數(shù)f1, f2指定要比較的文件的路徑??蛇x參數(shù)shallow指定比較文件時(shí)是否需要考慮文件本身的屬性(通過os.stat函數(shù)可以獲得文件屬性)。如果文件內(nèi)容匹配,函數(shù)返回True,否則返回False。

filecmp.cmpfiles(dir1, dir2, common[, shallow]):

比較兩個文件夾內(nèi)指定文件是否相等。參數(shù)dir1, dir2指定要比較的文件夾,參數(shù)common指定要比較的文件名列表。函數(shù)返回包含3個list元素的元組,分別表示匹配、不匹配以及錯誤的文件列表。錯誤的文件指的是不存在的文件,或文件被瑣定不可讀,或沒權(quán)限讀文件,或者由于其他原因訪問不了該文件。

filecmp模塊中定義了一個dircmp類,用于比較文件夾,通過該類比較兩個文件夾,可以獲取一些詳細(xì)的比較結(jié)果(如只在A文件夾存在的文件列表),并支持子文件夾的遞歸比較。

dircmp提供了三個方法用于報(bào)告比較的結(jié)果:

?report():只比較指定文件夾中的內(nèi)容(文件與文件夾)
?report_partial_closure():比較文件夾及第一級子文件夾的內(nèi)容
?report_full_closure():遞歸比較所有的文件夾的內(nèi)容
dircmp還提供了下面這些屬性用于獲取比較的詳細(xì)結(jié)果:

?left_list:左邊文件夾中的文件與文件夾列表;
?right_list:右邊文件夾中的文件與文件夾列表;
?common:兩邊文件夾中都存在的文件或文件夾;
?left_only:只在左邊文件夾中存在的文件或文件夾;
?right_only:只在右邊文件夾中存在的文件或文件夾;
?common_dirs:兩邊文件夾都存在的子文件夾;
?common_files:兩邊文件夾都存在的子文件;
?common_funny:兩邊文件夾都存在的子文件夾;
?same_files:匹配的文件;
?diff_files:不匹配的文件;
?funny_files:兩邊文件夾中都存在,但無法比較的文件;
?subdirs:我沒看明白這個屬性的意思,python手冊中的解釋如下:A dictionary mapping names in common_dirs to dircmp objects

簡單就是美!我只要文件比較的結(jié)果,不想去關(guān)心文件是如何是比較的,hey,就用python吧~~

數(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(), // 加隨機(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)的第一個參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(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ù)說明請參見: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 = '請輸入'+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); }