I am attempting to create a list of video objects, which have a name attribute which is set on initiation and then other attrs. that are loaded from ffprobe call fetching metadata. The ffmpeg calls are obviously slower to run, so I have written the class as follows:
class Video:
def __init__(self, path, name):
self.name = name
self.path = path
def get_length(self):
if self.length:
return self.length
else:
self.length = slow_function()
return self.length
This way I can just fetch the attribute at a point of time where I need to reference the attr and the value is "set" on the "get" call.
Is this the proper way to do this? Is there a better way?
Thanks.