python實(shí)現(xiàn)批量檢查兩個(gè)對(duì)應(yīng)的txt文件的行數(shù)是否一致?相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
代碼如下:
#coding=utf-8 import os, glob import numpy as np path2 = 'temp//1//' path3 = 'temp//2//' file_one_list = glob.glob(path2 + "*.txt") file_two_list = glob.glob(path3 + "*.txt") print(len(file_one_list)) for item in (file_one_list): base_name = os.path.basename(item) with open(item,'r') as f: lines_one=f.readlines() cur_file_path = os.path.join(path3, base_name) if os.path.exists(cur_file_path): with open(cur_file_path,'r') as f: lines_two=f.readlines() if len(lines_one)!=len(lines_two): print("檢測(cè)框不對(duì)應(yīng):",base_name) else: print("不在在文件",base_name)
分享標(biāo)題:python實(shí)現(xiàn)批量檢查兩個(gè)對(duì)應(yīng)的txt文件的行數(shù)是否一致-創(chuàng)新互聯(lián)
文章位置:http://aaarwkj.com/article18/cdpegp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、企業(yè)網(wǎng)站制作、外貿(mào)建站、搜索引擎優(yōu)化、商城網(wǎng)站、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容