I am learning about classes in python right now. My apologies if my language is a little sloppy, but I'm still trying to understand exactly how classes work.
While working through some projects of my own, I often find myself wanting to add an object, upon initialization, to a list so I can keep a track of all the objects I have made of that type. I have been trying to do this in the following way:
Try the following:
>>> class A(): ... my_list =  ... def __init__(self): ... A.my_list.append(self) ... >>> >>> a = A() >>> A.my_list [<__main__.A instance at 0x0000000002563548>] >>> b = A() >>> A.my_list [<__main__.A instance at 0x0000000002563548>, <__main__.A instance at 0x00000000025FB408>]