python iterate over instances of class

Solutions on MaxInterview for python iterate over instances of class by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "python iterate over instances of class"
Alix
24 Mar 2020
1class IterRegistry(type):
2    def __iter__(cls):
3        return iter(cls._registry)
4
5class Person(object):
6    __metaclass__ = IterRegistry
7    _registry = []
8
9    def __init__(self, name):
10        self._registry.append(self)
11        self.name = name