Extending base class methods
Steve Juranich
sjuranic at gmail.com
Tue Apr 19 11:49:25 EDT 2005
On 19 Apr 2005 08:27:28 -0700, henrikpierrou at hotmail.com
<henrikpierrou at hotmail.com> wrote:
> Ok, i'll try that. But what about the recommendation in the tutorial,
> is that not possible?
In the new (2.4) version of the Tutorial, that statement has been
removed. What you're using has been called "old-style" classes for
quite a while now (since 2.0?). Any new Python code should really be
using the "new-style" classes (inherit from "object" and use things
like "super".
But FWIW, it appears to still work with Python 2.4:
#---------- <snip FILE="Foo.py"> -----------------
class Foo:
def foo(self):
print "foo"
class Bar(Foo):
def foo(self):
print "bar"
Foo.foo(self)
#----------- </snip> ------------
# Now in the Python interpreter:
>>> from Foo import *
>>> f = Foo()
>>> f.foo()
foo
>>> b = Bar()
>>> b.foo()
bar
foo
So nothing jumps out to me that you did obviously wrong, sorry. But
in general my advice would be to switch to using "new-style" classes.
HTH
--
Steve Juranich
Tucson, AZ
USA
More information about the Python-list
mailing list