error in tutorial for 3.0, section 9.3.3

Michiel Overtoom motoom at xs4all.nl
Sat May 23 11:04:52 EDT 2009


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



More information about the Python-list mailing list