[Tutor] Where's the Walrus?

Rick Pasotto rick@niof.net
Tue, 20 Feb 2001 23:34:03 -0500


1) next_personality is a method so python needs the parens when it is called.

2) your definition of next_personality should have a 'self' arg.

3) self.which will become a 4 which is out of range. The way I code this
   type of situation is:

	self.which = (self.which + 1) % 4

   (instead of using an if statement)
   which makes sure self.which is only 0, 1, 2, or 3.

On Tue, Feb 20, 2001 at 06:38:22PM -0900, Tim Johnson wrote:
> Hello:
> 	I'm creating my first object.
> I have a method to advance an index.  
> The method doesn't respond.
> code is below:
> #######################################################
> 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
> 	def next_personality():
> 		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
> ally_oop.next_personality
> print ally_oop
> #######################################################
> FYI: Am coming from a background in C++
> but please don't hold that against me :)
> TIA
> --
> Tim Johnson
> -----------
> "Of all manifestations of power,
>  restraint impresses the most."
>  -Thucydides
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
"Half of the American people never read a newspaper. Half never voted for
President. One hopes it is the same half."
		-- Gore Vidal
		   Rick Pasotto email: rickp@telocity.com