Overriding a method in an instance
Martyn Quick
mrq at for.mat.bham.ac.uk
Wed May 2 05:43:42 EDT 2001
I was wondering what the correct way to change the definition of a method
of an instance of a class is. The following seems to work:
class TestClass:
def func(self):
print "1"
def newfunc():
print "2"
instance = TestClass()
instance.func = newfunc
Whereas, trying to redefine instance.func doesn't work.
Is the above the right way to change this method? [Is there anyway of
doing it without having to introduce "newfunc" as above?]
Martyn
--------------------------------------------------------
Dr. Martyn Quick (Research Fellow in Pure Mathematics)
University of Birmingham, Edgbaston, Birmingham, UK.
http://www.mat.bham.ac.uk/M.R.Quick
More information about the Python-list
mailing list