I want to find an instance of a class, where an attribute has a certain value:
import numpy as np
import inspect
import matplotlib.pyplot as plt
class Frame():
def __init__(self, img, idx):
self.image = img
self.idx = idx
for i in range(10):
img = np.random.randint(0, high=255, size=(720, 1280, 3), dtype=np.uint8) # generate a random, noisy image
Frame(img, i)
# Pseudo Code below:
frame = inspect.getmembers(Frame, idx=5) # find an instance of a class where the index is equal to 5
plt.imshow(frame.img)
From your example it looks like you are mixing two things: defining a Frame object (which contains an image) and defining a collection of Frames (which contains multiple frames, indexed so you can access them as you prefer).
So it looks like a xy problem: you probably just need to save Frame instances in a dictionary/list type of collection and then access the Frame you need.
Anyway, you can access the value of an attribute of an object using getattr.