Python中对象可以添加属性

转载Python 类对象与实例对象源码分析

当我在看cifar10_input.py文件中read_cifar10方法时,出现了result对象,进行属性赋值result.height = size,但是result是一个object对象,没有height属性,看到上面那个帖子才明白原因。

def read_cifar10(filename_queue):
    class CIFAR10Record(object):
        pass
    result = CIFAR10Record()

    label_bytes = 1
    result.height = 32//添加新属性,只属于result
    result.width = 32
    result.depth = 3
    image_bytes = result.height * result.width * result.depth

你可能感兴趣的:(深度学习与计算机视觉,python)