Apr-10-2020, 01:50 PM
(This post was last modified: Apr-10-2020, 01:50 PM by deanhystad.)
Since each image always has the same attributes, you could save even more space using slots. Classes that use slots instead of __dict___ provide faster access and have a smaller memory footprint.
If CustomImage is immutable you could also use a named tuple (import collections).
class CustomImage(): #my custom image class __slots__ = 'name', 'path', 'size', 'ext', 'avg' def __init__(self, name, path, size, rgb, ext="png"): self.name = name self.path = path self.size = size self.ext = ext self.avg = rgbWith slots you cannot add an attribute to the class. You can access or set attribute values, but I could not do custimg.rating = 4 because there is no slot for "rating".
If CustomImage is immutable you could also use a named tuple (import collections).