Subclassing a read-only class
Gerhard =?unknown-8bit?Q?H=E4ring?=
gh_pythonlist at gmx.de
Tue Feb 19 04:44:09 EST 2002
Le 18/02/02 ? 16:21, Alex Martelli écrivit:
> Gerhard H?ring wrote:
>
> > Hello,
> >
> > For compatibility testing, I'd like to put an additional method into
> > window object I get from the curses module. Unfortunately, if I try to
> > do so, I get:
> >
> > TypeError: object has read-only attributes
> >
> > I'm pretty sure there is a solution, probably with a proxy object. But
> > currently I just don't get it.
>
> You can generally substitute automatic-delegation in lieu of
> inheritance (as long as nobody is so uncouth as to typetest,
> e.g. with isinstance -- in which case, you're in trouble).
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295 gives
> a simple example ('inheriting' [via automatic delegation] from a
> file object back in Python 2.0 / 2.1 when you couldn't actually
> just subclass file as you can today) -- I hope you find the idea
> easy to adapt to your specific needs.
Thanks, that was what I was after. I just didn't remember where to find
an example of this pattern.
Gerhard
--
This sig powered by Python!
Außentemperatur in München: 4.0 °C Wind: 6.1 m/s
More information about the Python-list
mailing list