[Tutor] Self

Terje Johan Abrahamsen terjeja@hotmail.com
Fri, 26 Jul 2002 19:43:13 +0000


How does really the self thing work?

Will these two examples actually work the same way, and is the only reason 
why one would use self is so one don't have to write the class name again 
and again?

class smurf:
    variable = 15

    def write(self):
        smurf.variable = smurf.variable + 1
        print smurf.variable

and:

class smurf:
    variable = 15

    def write(self):
        self.variable = self.variable + 1
        print self.variable

Is there any reason why to use the first over the second or opposite? And, 
in the first one, why do I have to write the self in 'def write(self):', or 
don't I have to?

Thanks in advance,
Terje

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx