Given a class that keeps a registry of its Objects:
class Person(object):
__registry = []
def __init__(self, name):
self.__registry.append(self)
self.name = name
How would I make the following code work (without using Person.__registry):
for personobject in Person:
print personobject
While researching I found a hint that one could go for a __metaclass__
with a __getitem__
-method. Any ideas how this would look like?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…