Small problem when overloading member functions...

Jeff Epler jepler at unpythonic.net
Wed Jan 8 16:15:02 EST 2003


You don't have to write anything so complicated to see that Python
doesn't work the way you want it to work.  For instance,

    def add_one(x):
        x = x + 1

    x = 1
    add_one(x)
    print x  # prints 1, not 2

If you really want to write 'setFunction', you'll have to do it
something like this:

    def setFunction(self, funcname, tofunc):
        setattr(self, funcname, tofunc)
        # OR
        # self.__dict__[funame] = tofunc

and call it like this:
    a.setFunction('myPrint', self.newPrint)

This is really a very odd thing to do, though...

Jeff





More information about the Python-list mailing list