In the code below, class A has a member function which is set to point to a function defined outside the class. in class B, the same function is set to the external pointer in the class definition. Calling the function for an object of type A will fail, because the self does not get passed to the function. But for B, the self gets passed. Why does the self get passed for B, but not for A?
def f1(s,a):
print s
print a
class A(object):
def __init__(self):
self.fp1 = f1
class B(object):
fp1 = f1
a=A()
b=B()
try:a.fp1("blaa")
except Exception, e: print `e`
try:b.fp1("bluu")
except Exception, e: print `e`
Output:
TypeError('f1() takes exactly 2 arguments (1 given)',)
<__main__.B object at 0x2ab0dacabed0>
bluu