Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python iterate over instances of class

class IterRegistry(type):
    def __iter__(cls):
        return iter(cls._registry)

class Person(object):
    __metaclass__ = IterRegistry
    _registry = []

    def __init__(self, name):
        self._registry.append(self)
        self.name = name
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #iterate #instances #class
ADD COMMENT
Topic
Name
5+2 =