multiple values for keyword argument
Patty
patty at cruzio.com
Tue Feb 1 14:08:54 EST 2011
----- Original Message -----
From: "Jean-Michel Pichavant" <jeanmichel at sequans.com>
To: "Patty" <patty at cruzio.com>
Cc: <python-list at python.org>
Sent: Tuesday, February 01, 2011 2:27 AM
Subject: Re: multiple values for keyword argument
> Patty wrote:
>>
>>> patty at cruzio.com wrote:
>>>> I have been avoiding understanding this 'self',
>>>> [snip]
>>>> Regards,
>>>>
>>>> Patty
>>>>
>>> What is to be understood ?? self references the instance. Did I miss
>>> something ?
>>>
>>> JM
>>>
>>>
>>>
>>
>> Yes, there was more. And it's been fully explained at this point.
>>
>> Patty
>
>
> Hmm... I re-read the thread just in case ... Anyway.
> I'd like to read suggestions for self replacements...
> Currently 'yo' have been proposed.
>
> I'm just curious, I promise I won't make any comment :D
>
> JM
>
>
Hi Jean-Michel -
I'm sorry. I was getting sensitive about being criticized (or trying to
re-explain what I learned and getting it terribly mangled). As it turns
out - Westley Martinez pointed out the link about the usage of 'self' :
http://en.wikipedia.org/wiki/Self_(computer_science) and these specific
two lines showed me why I had been thinking I (we) could replace the word
'self' with any descriptive word (variable) I want. I was thinking of
'self' as a variable and not "In Python, there is no keyword for this, but
it exists as the name of the obligatory first argument of all member
functions. Conventionally, the name self is used."
And since I come from a C background, I thought I could do the following
(which the wiki page mentions) :} ) , thus I wanted to use an invented
variable name that makes sense to me and helped me as programmer remember
where I was in my program when I went and tried to reassign new values,
basically override my object at will. But this is what I did not realize:
>> "the assignment does not modify the original object, only changing which
>> object that the rest of the code in the method refers to" <<
"Some languages, such as Objective-C, allow assignment to self, although it
is deprecated."
And then after the thread ended - I read this in the wiki page which totally
explains everything -- "Early versions of C++ would let the this pointer be
changed; by doing so a programmer could change which object a method was
working on" and I learned C++ from an early version so this is Precisely
what I thought I could do -- I was envisioning having my object (member
function) and then as my program forked different paths, well I thought I
could do this very program design. Hopefully that makes more sense as to
why I would change the 'name of the obligatory first argument of all member
functions'.
As other people pointed out, you _can_ make up your own name, 'yo' or
anything else, it is by _convention_ to use 'self' and by doing your own
thing, could develop a bad habit.
Regards,
Patty
More information about the Python-list
mailing list