Trouble with inheritance and self
Erik Max Francis
max at alcyone.com
Fri Jan 17 08:14:01 EST 2003
Boethius wrote:
> I have 2 classes (A and B). Both have a render method that returns a
> string.
> The only difference between A and B's render is the first part of the
> string (header).
>
> B inherits from A and uses A's render with its own header (see code
> below).
The issue looks to be one of bound vs. unbound methods. An unbound
method requires an explicit self argument; a bound method already is
"attached" to one and thus doesn't need one.
> class B(A):
>
> def _header(self):
> return "B's header"
>
> def render(self):
> return A.render(self, header=self._header)
Try
return A.render(self, header=B._header)
here instead.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ Weakness of attitude becomes weakness of character.
\__/ Albert Einstein
7 Sisters Productions / http://www.7sisters.com/
Web design for the future.
More information about the Python-list
mailing list