Код: Выделить всё
T = TypeVar('T')
S = TypeVar('S')
def iter_attribute(outer: Iterable[T], attribute: str) -> Iterable[S]:
for item in outer:
yield from getattr(item, attribute)
Код: Выделить всё
class A:
a: str
def __init__(self, a: str):
self.a = a
a: str
for a in iter_attribute([A('a'), A('b'), A('c')], 'b'):
print(a)
Подробнее здесь: https://stackoverflow.com/questions/786 ... e-property