references/pointers in Python?
Patrick K. O'Brien
pobrien at orbtech.com
Thu Sep 13 21:35:21 EDT 2001
That's the way I starting to go. But class A *is* under my control, so I'll
bite - what is the better way to do this?
---
Patrick K. O'Brien
Orbtech (http://www.orbtech.com)
"I am, therefore I think."
"Gordon McMillan" <gmcm at hypernet.com> wrote in message
news:Xns911BC3D19BBC5gmcmhypernetcom at 199.171.54.214...
> Lots of ways you could do this. Probably the most "pythonic" (at least,
> before Python 2.2) would be:
>
> class B:
> _attrs = ('toggle01', 'toggle02', 'toggle03')
> def __init__(self, other):
> self.__dict__['other'] = other
> def __getattr__(self, nm):
> if nm in self._attrs:
> return getattr(self.other, nm)
> raise AttributeError, nm
> def __setattr__(self, nm, val):
> if nm in self._attrs:
> return setattr(self.other, nm, val)
> raise AttributeError, nm
>
> This is a typical kind of pattern where class A is out of your control.
> Where class A *is* under your control, I think you'll find a better
> way to do it (once you've unlearned all the tricks you need to survive
> in other object models).
>
> - Gordon
>
>
More information about the Python-list
mailing list