Vincent writes:

> you kinda expect MyClass to have counter in it.

Yeah, that makes sense. These instance variables are often initialized in the __init__ method:


class Counter(object):
    def __init__(self,initialvalue):
        self.value=initialvalue
    def inc(self):
        self.value+=1
    def dec(self):
        self.value-=1

beans=Counter(123)
beans.inc()
beans.inc()
beans.dec()
print beans.value

# the output of the program is: 124

Greetings,


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to