Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
del self does not work!
#1
Hello,

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 removed
    
Here I wanted to delete self if the len(self) is equal zero but it did not work. What can I do?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020