Найдите экземпляр класса на основе значения атрибута [закрыто] ⇐ Python

Программы на Python
Anonymous
Найдите экземпляр класса на основе значения атрибута [закрыто]

Сообщение Anonymous »

Я хочу найти экземпляр класса, атрибут которого имеет определенное значение:

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)


Подробнее здесь: https://stackoverflow.com/questions/490 ... -attribute

Вернуться в «Python»