📜  python 遍历类的实例 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:59.556000             🧑  作者: Mango

代码示例1
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