bound member functions ?

Achim Domma achim.domma at syynx.de
Mon Oct 8 04:41:48 EDT 2001


Hi,

I have tried the following code :

--- code --------------------------
class Dummy:
    def __init__(self,val):
        self.val = val

    def mult(self,fac):
        return self.val * fac


obj = Dummy(5)
mult = obj.mult
print mult(5)
------------------------------------

The script prins 25 as I expected. If I change now the last three lines to

--- code ---------------------------
...
mult = Dummy(7).mult
print mult(5)
-------------------------------------

I still get 35. What's about reference counting in this case ? Is there a
refernce hidden in mult which keeps 'Dummy(7)' alive ? Can I be sure, that
the object constructed by Dummy(7) is not destroyed after this line ?

greetings
Achim





More information about the Python-list mailing list