Let’s say I have created two objects from class foo and now want to combine the two. How, if at all possible, can I accomplish that within a function like this:
def combine(first, second):
first.value += second.value
del second #this doesn't work, though first.value *does* get changed
instead of doing something like
def combine(first, second):
first.value += second.value
in the function and putting del second immediately after the function call?
No. All
deldoes against names is unbind them. This only removes the local reference. The object will be destroyed when there are no references to it anywhere, or all the references are in a reference loop.