Can I access the class attributes from a method added at runtime? (My
experience says no.)
I experimented with the following code:


class myclass(object):
    myattr = "myattr"

instance = myclass()
def method(x):
    print x

instance.method = method
instance.method("hello world")

inst2 = myclass()
#inst2.method("inst2")

def meth2(x):
    print x.myattr

myclass.ujmeth = meth2
inst2 = myclass()
inst2.ujmeth()


############
The output:
##########

hello world
myattr

################

So it seems to me, if you add a method to an instance, the method will
not get "self" as parameter.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to