Chaning instance methods

Jody Winston jody at ldgo.columbia.edu
Tue Apr 6 16:34:08 EDT 1999


I don't understand how to change instance methods.  For example:

class Foo:
	def __init__(self):
		self.data = 42
	def m(self):
		print "Foo.m"
		print dir(self)

def m2(self):
	print "m2"
	print dir(self)

f = Foo()
f.m()
# this fails
# f.m = m2
# f.m()
Foo.m = m2 # Changes all instances of Foo.m
f.m()

f2 = Foo()
f2.m()

What am I forgetting?

-- 
Jody Winston
Manager SeisRes
Lamont-Doherty Earth Observatory
RT 9W, Palisades, NY 10964
jody at ldeo.columbia.edu, 914 365 8526, Fax 914 359 1631 

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.






More information about the Python-list mailing list