檔案解析,在mysql配置和檢查項一樣的專案

weixin_44462689發表於2020-11-29
在這裡插入程式碼片

#coding:utf-8
import  pandas as pd
import re
begin_start =''
soft_bin_start =''
soft_bin_end =''
onetest_strart=[]
onetest_end =[]
df = pd.read_excel(r'C:\Users\曾標\Desktop\aa.xlsx')
with open(r'C:\Users\曾標\Desktop\aa.txt')as f:
    line_list=[x for x in f.read().split("\n")]
    for index ,x in enumerate(line_list):
        if x =='begin':
            begin_start =index
        elif x=='softbin':
            soft_bin_start =index
        elif x =='softbinend':
            soft_bin_end =index
        elif x=='onetest' or x =='chipinfo':
            onetest_strart.append(index)
        elif x=='onetestend' or x =='chipinfoend':
            onetest_end.append(index)
# print(begin_start)
# print(soft_bin_end)
# print(soft_bin_start)
# print(onetest_strart)
# print(onetest_end)

'''檢測是否為miss:'''
#拿到所有的要檢測miss的專案
print(df[df['d']=='miss'])#1345需要檢測miss
#拿到需要檢測miss的列表
miss_df=df[df['d']=='miss']['c']
#非miss檢測
nomiss_df = df[df['d']!='miss']
print(miss_df.values)#變成列表
check_list=[]
for i in range(begin_start+1,soft_bin_start):
    #要檢測的專案  print()
    check_list.append(  line_list[i].split(':')[0])
print(check_list)
#拿到所有專案的列表
for i in miss_df:
    if i not in check_list:
        print(i)
        print("sss")

#然後檢查其他的
print("檢查非miss")
print(nomiss_df)
for i in range(begin_start+1,soft_bin_start):
    ##拿到該檢查項需要檢測的專案 和值:
    check_txt = line_list[i].split(':')[0]
    if not check_txt: #begin 和testinfo之間的空白需要跳出
        break
    check_value = line_list[i].split(':')[1].strip() ##一定要去掉空白符號
    check_df =nomiss_df[nomiss_df['c']==check_txt] #拿到cc1 需要檢測專案
    for index ,row in check_df.iterrows():
        if row['d']=='empty':#檢測是否有為空
            if  check_value =='':
                print("empty error")
        if row['d']=='format':#檢測format
                com=re.compile(row['epxr'])
                reslut = re.match(com,check_value)
                if not reslut:
                    print("format error")
        if row['d'] == 'length':  # 檢測forma
            if  len(check_value)> row['min'] and   len(check_value)> row['max']:
                print("length error")



相關文章