"prove"

Marco Mariani marco at sferacarta.com
Thu May 8 09:59:21 EDT 2008


Lucas Prado Melo wrote:

> How could I "prove" to someone that python accepts this syntax using
> the documentation (I couldn't find it anywhere):
> classname.functionname(objectname)

TUtorial 9.3.4, method objects

What exactly happens when a method is called? You may have noticed that 
x.f() was called without an argument above, even though the function 
definition for f specified an argument. What happened to the argument? 
Surely Python raises an exception when a function that requires an 
argument is called without any -- even if the argument isn't actually 
used...

Actually, you may have guessed the answer: the special thing about 
methods is that the object is passed as the first argument of the 
function. In our example, the call x.f() is exactly equivalent to 
MyClass.f(x). In general, calling a method with a list of n arguments is 
equivalent to calling the corresponding function with an argument list 
that is created by inserting the method's object before the first argument.



More information about the Python-list mailing list