Answers for "python iterate for each class"

0

iterate through attributes of class python

L = [[getattr(self, attr), attr] for attr in dir(self) if not attr.startswith("__")]
Posted by: Guest on November-23-2020
-1

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
Posted by: Guest on March-14-2020

Python Answers by Framework

Browse Popular Code Answers by Language