adding instance methods after instantiation

Lee Harr missive at frontiernet.net
Sat Jun 23 07:45:06 EDT 2001


This is what I am hoping to do:

class c:
  def __init__(self):
    self.a1 = 1
  def m1(self):
    self.a2 = 2

def m2(self): #note, outside of class c definition
  self.a3 = 3

c1 = c()
c1.m2 = m2

c1.m2()
a3



Is there some way to make m2 an instance method so that
it will automatically get passed c1 as its first
argument?

Is this a reasonable thing to want to do?
     




More information about the Python-list mailing list