[Tutor] Where's the Walrus?
Bruce Sass
bsass@freenet.edmonton.ab.ca
Tue, 20 Feb 2001 22:04:02 -0700 (MST)
Hi,
A couple of small changes...
---8<---
class schiz:
def __init__(self):
self.moods = ["I'm a little teapot", "I am the Walrus",
"I hate broccoli", "I'm the Jolly Green Giant"]
self.which = 0
# my code doesn't even get called, or so it appears
# *vvv* this needed the "self" reference
def next_personality(self):
print "next personality"
if self.which < 4:
self.which = self.which + 1
print "next"
else:
self.which = 0
print "first"
def __str__(self):
return self.moods[self.which]
def __repr__(self):
return self.moods[self.which]
def __call__(self):
return self.next_personality()
ally_oop = schiz()
print ally_oop
# *vvv* forgot the "()"
ally_oop.next_personality()
print ally_oop
# *vvv* this tests the __call__ method
ally_oop()
print ally_oop
--->8---
gets this output...
I'm a little teapot
next personality
next
I am the Walrus
next personality
next
I hate broccoli
- Bruce