how do i create such a thing?

Lowell Kirsh lkirsh at cs.ubc.ca
Tue Feb 1 20:39:52 EST 2005


I'm not sure I get it. What's the purpose of using a delegate rather 
than having the object itself supply the return value?

Alex Martelli wrote:
> Lowell Kirsh <lkirsh at cs.ubc.ca> wrote:
> 
> 
>>What might these exceptions be?
>>
>>
>>>It's HIGHLY advisable to have your __getattr__ methods raise
>>>AttributeError for any requested name that starts and ends with double
>>>underscores, possibly with some specific and specifically designed
>>>exceptions.
> 
> 
> For example, delegation of such requests to some other object:
>     def __getattr__(self, name):
>         return getattr(self._delegate, name)
> 
> In such cases you may decide you do not need to block __specials__,
> because you're OK with having self._delegate supply them or be
> responsible to raise AttributeError if necessary.
> 
> 
> Alex



More information about the Python-list mailing list