I am making a program where I need to iterate through every option in a class to perform actions to each object, to do that I made an 'IterRegistry' Class to turn the metaclass of my objects to iterable but for some reason, it still isn't working.
class IterRegistry(type):
def __iter__(cls):
return iter(cls._registry)
class TreeLine(object):
__metaclass__ = IterRegistry
_registry = []
def __init__(self, earnings, buy_price):
self._registry.append(self)
self.earnings = earnings
self.buy_prince = buy_price
TreeLine(0, 0)
TreeLine(0, 7)
for i in TreeLine:
print(i)
I just get the error message: File "/Users/PycharmProjects/AISTUFF/venv/OSI@.py", line 23, in for i in TreeLine: TypeError: 'type' object is not iterable