2.2 properties and subclasses
Miles Egan
miles at rddac.com
Mon May 19 20:31:38 EDT 2003
In article <mailman.1053380733.4384.python-list at python.org>, Tim Peters wrote:
> [Miles Egan]
> If you think that's what you want (I don't recommend it), you could, e.g.,
> write the stuff this way instead:
>
> class BaseClass(object):
> def __init__(self):
> self._prop = "BASE"
>
> def get_prop(self): return self._prop
> prop = property(lambda self: self.get_prop()) # the only change
>
> class SubClass(BaseClass):
> def get_prop(self): return "SUB"
>
> Then the (still shared) prop dynamically looks up which get_prop() to use on
> each invocation, and only get_prop needs to be overridden in SubClass.
This is the behavior I was expecting. I guess what I really want here
is a simple way to implement properties in the base class and
intercept access to them in some cases in subclasses (lazy
initialization, etc).
Why don't you recommend this? It seems like a pretty natural solution
to my current problem.
Thanks for your help.
--
miles egan
miles at rddac.com
reverse the domain name to find me
OpenPGP/GPG Key 0x01F53D51 @ wwwkeys.us.pgp.net
More information about the Python-list
mailing list