"Bjoern Schliessmann" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |> - only functions being attributes of a class...
|What, IYHO, is the difference between a method and a function? A method is a function accessed as an attribute of a class or instance. As an object type, it is a *runtime* function wrapper. |> (ok, I know, you meant "functions declared within a class> statement"). | I think that those functions _are_ special ones Thinking does not make things so. |since the compiler is able to make "method(instance, a, b)" out of |"instance.method(a, b)". No it does not. The method wrapping is done at runtine. The compiler is ignorant of the wrapping that will be done. >>> class C: def meth(self): pass >>> c = C() >>> import dis >>> def f(): return c.meth() >>> dis.dis(f) 1 0 LOAD_GLOBAL 0 (c) 3 LOAD_ATTR 1 (meth) 6 CALL_FUNCTION 0 9 RETURN_VALUE The function gets wrapped as a bound method as part of LOAD_ATTR. When the compiler sees <expr>(args), it does not know and does not care about the particular type that <expr> will become. It just assumes that it will be callable and emits the code to call it. Consider >>> def g(): return C() >>> dis.dis(g) 1 0 LOAD_GLOBAL 0 (C) 3 CALL_FUNCTION 0 6 RETURN_VALUE It does not notice and does not care that 'C' will be bound to a class. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list