I am building a python program which will be working with thousands of python objects. I am curious about what is the most elegant way to organize them, and I am also not clear on when things get copied in python.
For example if I have a manager object which has a list of thousands of objects, but it also has a dictionary with keys to each of those thousands of objects, do the objects exist twice in memory? If I were to change the properties of an object in the list, will it also change the properties of the corresponding object in the dict?
I can't find much good reading on this, so if someone could point me in the right direction, that would be helpful.
Here is what I am thinking:
class Manager():
def __init__(self,list_of_objects):
self.myobjects = []
self.myobjectsdict= {}
self.myobjects = list_of_objects
for object in self.myobjects:
self.myobjectsdict[object.name] = object
Then, if I were to create a second manager object and give it some of the first manager's objects, would they be copies? Or would changes made by the second manager apply to the objects owed by the first? For instance, what happens here:
manager2 = Manager(manager1.myobjects[5000:10000])
manager2.myobjects[71].name = "newname"
Does the name change for that object in the first manager? Will the dict key still be the old name?
Finally, is a list or dict of thousands of objects really the best way to organize lots of python objects, or is there a better way I haven't come across? Thanks so much for any help.