[Edu-sig] Python @ Education: What are your problems?

Guido van Rossum guido@python.org
Fri, 07 Jun 2002 15:04:39 -0400


> ###
> >>> class Parent:
> ...     def sayHello(self):
> ...         print "hello"
> ...
> >>> class Child(Parent):
> ...     def sayHello(self):
> ...         print "My mom says:",
> self.__class__.__bases__[0].sayHello(self)
> ...
> >>> p, c = Parent(), Child()
> >>> p.sayHello()
> hello
> >>> c.sayHello()
> My mom says: hello
> ###
> 
> but as you can tell, this is really awkward!

It is also wrong.  Consider

>>> class GrandChild(Child): pass
... 
>>> g = GrandChild()
>>> g.sayHello()
(infinite loop)

--Guido van Rossum (home page: http://www.python.org/~guido/)