Help, re SMTP posting / RFC822

Fredrik Lundh fredrik at pythonware.com
Fri Sep 17 03:28:17 EDT 1999


Benjamin Schollnick <junkster at nospam.rochester.rr.com> wrote:
> 2) I'm confused about using variables from a OBJECT, inside a routine
> of said object.  I was able to
> write the entire POP3.PY code without using SELF.<VAR NAME> and ran 
> it.  It seemed that certain
> routines needed SELF, and others would seem to work fine w/o the 
> self.  Have I used self correctly,
> or horribly misused it?  (See full code below)

not sure what you mean here (cannot really tell from
the code), so how about me telling you what self is,
and let you figure the rest out yourself?

here's the short version of the story:

    -- classes have methods, which works pretty
       much like ordinary functions.

    -- when you call an instance method, python
       automatically passes the instance itself as the
       first argument.  somewhat simplified,

            spam.egg(1)

        becomes:

            egg(spam, 1)

    -- by convention, the first argument is named
       "self", and the above method is thus usually
       written like:

            def egg(self, value):
                print value

so in other words, use self to refer to members of
the object instance inside a method.  don't use it
if you're referring to arguments, local variables, or
global variables.

hope this helps!

</F>





More information about the Python-list mailing list