I have a python object which is essentially a collection of other object instances. You can append other objects to it (which it just stores in a list). It is created when reading a file, eg:
def file_reader(file):
obj = MyCollection()
for line in file:
other_obj = line_reader(line)
obj.append(other_obj)
return obj
If I then try to overwrite the object later (by reading a different file), the original data is not deleted, the object is just extended. Strangely, this seems to happen if I use different references:
obj1 = file_reader(file)
obj2 = file_reader(file1)
I suspect I have some kind of problem with circular referencing, but I can't quite grasp the logic. Anyone have an idea?
Edit: The essential part of MyCollection looks like:
class MyCollection(object):
def __init__(self, objs = []):
self.objs = objs
def append(self, obj):
self.objs.append(obj)