|
![](/i/fill.gif) |
On 10/20/2012 23:39, Warp wrote:
> Darren New<dne### [at] san rr com> wrote:
>> On 10/16/2012 5:06, Warp wrote:
>>> Well, for one, methods taking 'self' as a parameter seems highly unusual
>
>> A function that takes "self" as the first argument is a method. Otherwise
>> it's a function.
>
> Well, duh. How does that change what I said?
Well, to be more specific, you can call a function two ways:
abc(xyz, pdq)
or
xyz.abc(pdq)
They both do the same thing, except the second syntax says "pass xyz as the
first argument to the function abc() found in the dictionary of the value of
xyz." So it's not really changing the syntax or declaring that it's a
method in any way. It's just saying "I expect you to invoke this in a way
that looks like a method, because I named the first argument 'self'." If you
wanted to invoke it on some other object, you could just as easily invoke
abc(that, pdq) and "self" would become "that".
It's a naming convention, nothing more. Unlike, say, the names of
constructors and destructors, which things like Java, C++, and C# treat as
special because they match the name of the enclosing class.
Remember, too, that names in Python are merely variables. A class doesn't
have a name, but only the variable(s)/dictionary key(s) to which it is
currently assigned. So there's no way to identify special properties of a
class, especially since you can modify the classes at run time.
--
Darren New, San Diego CA, USA (PST)
"They're the 1-800-#-GORILA of the telecom business."
Post a reply to this message
|
![](/i/fill.gif) |