Trouble with inheritance and self
Mike Meyer
mwm at mired.org
Fri Jan 17 13:01:23 EST 2003
boethius at techie.com (Boethius) writes:
> ---------code-------------------------------------------------------
> class A(object):
>
> def _header(self):
> return "A's header"
>
> def render(self, header = _header):
> return header(self) + 'Foo Bar Baz'
>
> class B(A):
>
> def _header(self):
> return "B's header"
>
> def render(self):
> return A.render(self, header=self._header)
Wouldn't this be a lot simpler if you just used straight inheritance?
class A(object):
_header = "A's header"
def render(self):
return self._header + 'Foo Bar Baz'
class B(A):
_header = "B's header"
I know this is probably just a "stripped to the minimum example", so
using inheritance may not work in your real problem. But it ought to
be worth a look.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list