how do i create such a thing?

Steve Holden steve at holdenweb.com
Tue Feb 1 20:47:14 EST 2005


Lowell Kirsh wrote:

> 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

The point is that you can keep a reference to some object, and it's the 
next best thing to having subclassed the object's class but with closer 
control.

regards
  Steve

A: Top-posting
Q: What puts things in the wrong order on newsgroup postings
-- 
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005          http://www.python.org/pycon/2005/
Steve Holden                           http://www.holdenweb.com/



More information about the Python-list mailing list