[Edu-sig] Python Quiz

David Handy cpif at handysoftware.com
Wed Sep 7 20:35:50 CEST 2005


On Tue, Sep 06, 2005 at 03:31:36PM -0700, Kirby Urner wrote:
> 
> class Shell:
> 
> 	def __init__(ghost):
> 		pass
> 
> 	def __repr__(ghost):
> 		return 'What famous Japanese cartoon?'
> 
> OK that was easy.  So how about:
> 
> class Shell (object):
> 
> 	def __init__(ghost):
> 		pass
> 
> 	def __repr__(ghost):
> 		return 'What famous Japanimation?'
> 
> Hint:  think "new-style class."
> 
> Kirby

I don't get it. You have two classes, both with a repr implementation, and
the second one happens to be a new-style class as indicated by its being
derived from "object". Was there more to it than that?

Just in case, I copied and pasted your new-style class definition into
kirby-ghost.py and tried it out with Python 2.3 on my machine, just to see
if there was some gotcha that I had overlooked. It works just fine for me:

[david at ujae stuff]$ python -i kirby-ghost.py
>>> dir()
['Shell', '__builtins__', '__doc__', '__file__', '__name__']
>>> s = Shell()
>>> s
What famous Japanimation?

Loving-Python-Quizzes-but-being-puzzled-by-this-one'ly-yours,
David H


More information about the Edu-sig mailing list