Can "self" crush itself?

n00m n00m at narod.ru
Wed Nov 25 06:45:56 CET 2009


> Whatever you rebind ‘self’ to inside the function...


Seems you are right! Thanks, Ben, for the lesson :-)


class Moo:
    cnt = 0
    def __init__(self, x):
        self.x = x
        self.__class__.cnt += 1
        if self.__class__.cnt > 2:
            self.crush_me()
    def crush_me(self):
        print 'Will self be crushed?'
        self = None
        print self

f = Moo(1)
g = Moo(2)
h = Moo(3)
print '================='
print h



Will self be crushed?
None
=================
<__main__.Moo instance at 0x00CC9468>



More information about the Python-list mailing list