Base-class method access
Joseph Barillari
jbarilla at princeton.edu
Mon Jul 15 22:56:24 EDT 2002
> Hi.
> Is it possible for a derived class to access overridden methods of its
> base class? For example:
>
>
> class Foo:
> def frob(): << this is incorrect; should be (self)
> print "Spam"
>
> class Bar(Foo):
> def frob(): << this is incorrect; should be (self)
> print "Eggs"
> # In C#, the syntax to call Foo's frob() would be
> # base.frob()
> <Insert Python-appropriate syntax for that call here>
>
> >> a = Bar()
> >> a.frob()
> Eggs
> Spam
>
> Is there a means of doing this in Python?
>
> Thanks in advance.
>
> --Joe
>
I found the solution in the Webware source code: invoke the method by
calling it as a method of the base class. My apologies for the
unnecessary email.
>>> class Foo:
... def frob(self):
... print "Spam"
...
>>> class Bar(Foo):
... def frob(self):
... print "Eggs"
... Foo.frob(self)
...
>>> a = Bar()
>>> a.frob()
Eggs
Spam
--Joe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 265 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20020715/9b405eb3/attachment.sig>
More information about the Python-list
mailing list