multiple values for keyword argument

Westley Martínez anikom15 at gmail.com
Tue Feb 1 03:36:12 CET 2011


In Python, self is simply the standard name used. You can use any name.
Consider this:
>>> class Spam:
...     def __init__(self):
...             print(self)
...             self = 'eggs'
...             print(self)
... 
>>> spam = Spam()
<__main__.Spam object at 0xb7224b4c>
eggs

When we have an instance method, here __init__, we always pass the
instance as the first argument. This is assigned as regular old
variable. It doesn't have any special restrictions. So when we refer
self to a string, self simply stops pointing to the object and points to
the string instead, but remember that each self is only contained in its
method, so all the other selfs in the class will still point to the
object.

On Mon, 2011-01-31 at 18:18 -0800, Patty wrote:

>  
> 
>         >----- Original Message ----- 
>         >From: Westley Martínez 
>         >To: python-list at python.org 
>         >Sent: Monday, January 31, 2011 3:27 PM
>         >Subject: Re: multiple values for keyword argument
>         
>         
>         >http://en.wikipedia.org/wiki/Self_(computer_science)
>          
>         Hello Westley:
>          
>         Thank you for the reference.  I saw something in it that I
>         think is what tripped me up in my understanding of 'self'.  I
>         printed out the page to absorb more later.  It helps me to
>         learn when the concept is introduced to me in terms of
>         comparison to other languages so I like this page.  Here are
>         the two lines from the wiki page, I was probably going to try
>         and 'assign to self' and expecting that I was modifying the
>         original object like it says.  In turn, that is what was
>         leading me to want to name 'self' anything I want, to jog my
>         memory as to 'where it came from' because '*I* am assigning
>         it'.  [I know I should be documenting my code clearly and my
>         memory shouldn't need to be jogged :} ].  
>         "Some languages, such as Objective-C, allow assignment to
>         this, although it is deprecated. Doing so can be very
>         misleading to maintenance programmers, because the assignment
>         does not modify the original object, only changing which
>         object that the rest of the code in the method refers to, and
>         can end with undefined behavior"
>          
>         Regards - 
>          
>         Patty
>         
>         
>         On Mon, 2011-01-31 at 13:20 -0800, Patty wrote: 
>         > 
>         > ----- Original Message ----- 
>         > From: "Jean-Michel Pichavant" <jeanmichel at sequans.com>
>         > To: <patty at cruzio.com>
>         > Cc: <python-list at python.org>
>         > Sent: Monday, January 31, 2011 11:35 AM
>         > Subject: Re: multiple values for keyword argument
>         > 
>         > 
>         > > 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
>         
>         
>         
>         
>         
>         ______________________________________________________________
>         
>         -- 
>         http://mail.python.org/mailman/listinfo/python-list


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110131/c8047664/attachment.html>


More information about the Python-list mailing list