拼写错误示例

问题:AttributeError: ‘str’ object has no attribute ‘endwith’


catdog_label = {"cats": 0, "dogs": 1}

data_info = list()
for root, dirs, _ in os.walk(data_dir):
    # 遍历类别
    for sub_dir in dirs:
        img_names = os.listdir(os.path.join(root, sub_dir))
        img_names = list(filter(lambda x: x.endwith('.jpg'), img_names))

在这里插入图片描述
解决:endwith改成endswith