Delete a instance passed by reference into a method

sccs cscs zorg724 at yahoo.fr
Mon Dec 3 17:53:20 EST 2007


Hello,
I am very surprising by the Python interpreter behavior : see code
I initialize a 'A' and a 'B', and i give a B instance reference to the  instance A in 'm1' method. I can modify (IN/OUT mode)  the 'i' attribute  (  aB.i = 10 ) , BUT I CANNOT DELETE "aB" into the fonction m1 ! the code "     del aB " or " aB= None" has no effect. 'aB' still exists when m1() is finsihed! WHY ? How can i do that?
Thank you.
Zorgi


class A(object):
       def __init__(self):
        pass
    def m1 (self, aB ):
        aB.i = 10
        del aB
        print "no more B"
        
class B(object):
    def __init__(self,i):
        self.i = i
    def __del__(self):
        print "delete B"

aA = A ()
aB = B ( i = 6)

unA.m1 (aB )
print str( aB .i )  #--->  Display 10, aB is not destroy !



             
---------------------------------
 Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071203/b8bfdc17/attachment.html>


More information about the Python-list mailing list