"jfj" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I don't understand. > We can take a function and attach it to an object, and then call it > as an instance method as long as it has at least one argument: > > ############# > class A: > pass > > def foo(x): > print x > > A.foo = foo > a=A() > a.foo() > ############# > > However this is not possible for another instance method: > > ############ > class A: > pass > > class B: > def foo(x,y) > print x,y > > b=B() > A.foo = b.foo > a=A() > > # error!!! > a.foo() > ############## > > Python complains that 'foo() takes exactly 2 arguments (1 given)'. > But by calling "b.foo(1)" we prove that it is indeed a function which > takes > exactly one argument. > > Isn't that inconsistent?
You called b.foo(1) but a.foo(). Note one argument in the first call and no arguments in the second call. Would you have called a.foo(1), you would have gotten the same result as with b.foo(1). I suppose that was just a small omission on your part, but what are you trying to do anyway? It's a very strange use of instance methods. -- http://mail.python.org/mailman/listinfo/python-list