How to keep track of class instances?
Toward the end of a program I'm looking to load a specific variable from all the instances of a class into a dictionary. For example: class Foo(): __init__(self): x = {} foo1 = Foo() foo2 = Foo() foo...etc. Let's say the number of instances will vary and I want the x dict from each instance of Foo() loaded into a new dict. How would I do that? The examples I've seen in SO assume one already has the list of instances. One way to keep track of instances is with a class variable: class A(object): instances = [] def __init__(self, foo): self.foo = foo A.instances.append(self) At the end of the