I am trying to find the best way to delete something, preferably without having to write in a lot of code.
In my project, I mimic chemical compounds - I have instances Elementassociated with other instances Elementusing the instance Bond. In chemistry, bonds often break, and I would like to have a clean way to do it. My current method is as follows
element1.removeBond(aBond)
element2.removeBond(aBond)
del aBond
I want to do something like
aBond.breakBond()
class Bond():
def breakBond(self):
self.start.removeBond(self)
self.end.removeBond(self)
del self
Alternatively, something like this would be fine
del aBond
class Bond():
def __del__(self):
self.start.removeBond(self)
self.end.removeBond(self)
del self
Is there any of these ways to make this preferable to others, or is there any other way to do this that I skip?