[Edu-sig] Retrospective: Our Open Source class including Python

Kirby Urner urnerk at qwest.net
Mon Jul 19 20:26:32 CEST 2004


> Good stuff.
> 
> I would only suggest you try to squeeze in something about the phenom one
> is
> observing when playing as follows.
> 
> >>> class Mammal(object):
> 	def eat(self): print 'Munch'
> 	def sleep(self): print 'Zzzzzz'
> 
> >>> hippo =Mammal()
> >>> hippo.eat()
> Munch
> >>> print hippo.eat
> <bound method Mammal.eat of <__main__.Mammal object at 0x00A8E490>>
> >>> eat=hippo.eat()
> Munch
> >>> print eat
> None

Indeed, I should include something along those lines.  

You're pointing out the difference between printing a result and returning
one.  Hippo.eat() prints to stdout (the terminal) but doesn't return
anything, so the variable set up to receive its output gets the default
return value for methods and functions (None) -- which is different than not
being defined at all.

My thanks to both yourself and David Handy for useful feedback.
Appreciated.

Kirby




More information about the Edu-sig mailing list