에러 삽질

if 문 괄호 생활화

ylab 2022. 4. 20. 12:57
import os
import glob
data_root = "C:\\Users\\user\\Downloads\\Image_train_remove_aug_again"
data_aug = os.listdir(data_root)

for i in range(len(data_aug)):
    try:
        name_list = data_aug[i].split('_')
        height = name_list[-2]
        weight = name_list[-1][:-8]
        BMI_ = (int(weight) / 100000) / ((int(height) / 100000) ** 2)
        if BMI_ > 25 and BMI_ < 35 :
            if ("orgin" in name_list) or ("fliped" in name_list):
                if os.path.exists(data_root):
                    os.remove(os.path.join(data_root, data_aug[i]))

    except:
        data_aug[i]=data_aug[i].replace(']','_')
        name_list = data_aug[i].split('_')
        height = name_list[-3]
        weight = name_list[-2]
        BMI_ = (int(weight) / 100000) / ((int(height) / 100000) ** 2)
        if BMI_ > 25 and BMI_ < 35 :
            if ("orgin" in name_list) or ("fliped" in name_list):
                if os.path.exists(data_root):
                    os.remove(os.path.join(data_root, data_aug[i]))

#data_aug

orgin or fliped에 괄호를 치지 않아 모두 지워지는 사태가 발생하였다.

괄호를 생활화 하자

그리고 더블체크 

생활화 하자.