how to give an object as argument for a method

Grant Edwards grante at visi.com
Thu Mar 7 21:15:06 EST 2002


In article <mailman.1015545375.27073.python-list at python.org>, Marco Herrn wrote:

>> If a function expects a parameter, then it should show up in
>> the function definition.  Methods are just functions whose
>> first parameter is expected to be an object reference.
> 
> Hmm, ok. All you say seems right to me. But what is a bit strange is,
> that I explicitly have to implement 'self', but don't give it as argument.

Ah, but you do.  You just put it before the name of the
function:

  objectName.methodName()
      |           |
      |            \_ This is the function name
       \
        \_ This is the "self" parameter      

The object who's name is "objectName" also defines the
namespace(s) which are to be searched for "methodName".

> If a have a method with the defininion 'f(self)' I call this method only
> with 'f()'.

Nope.  You can't call f like that.  You have to do either
  objName.f()
or
  f(objName) 

> So the declaration doesn't look the same like the call.

  It can, if you want.

> So you think it will stay this way, that one has to implement
> it for himself. That's ok. I can live with that. But I don't
> see any disadvantage, when changing the language so that a
> 'self' statement is always available.

-- 
Grant Edwards                   grante             Yow!  If I felt any more
                                  at               SOPHISTICATED I would DIE
                               visi.com            of EMBARRASSMENT!



More information about the Python-list mailing list