Mar-30-2021, 08:41 AM
Hello,
Here is my class:
Here is my class:
class EO: #TODO : add method to display/print the object fragile=True #EO is «destroyed» when 1 bit is lost #TODO update this hack def __init__(self,state,n,*extraargs): self.state=state self.bits=[qubit(self,k,extraargs) for k in range(n)] self.extraargs=extraargs def __len__(self): return len(self.bits) def losebit(self, k): """Implements loss of bit(k). It should already be removed from all datastructures""" if not self.fragile : raise NotImplementedError('Only fragile losses implementend yet') else : self.state=False for qb in self.bits[k+1:] : qb.pos -=1 del self.bits[k] #if len(self)==0 : del self #doesn’t work. ## But actually should happen automatically by garbage collection when last ref ## is removedHere I wanted to delete self if the len(self) is equal zero but it did not work. What can I do?