[Tutor] ftp program

Rich Krauter rmkrauter at yahoo.com
Sat Aug 28 18:45:59 CEST 2004


Lloyd Kvam wrote:
> On Sat, 2004-08-28 at 02:54, Rich Krauter wrote:
> 
>>(long post full of open-ended questions follows)
> 
> 
>>1. I use __getattr__ to handle a single attribute lookup - __getattr__ 
>>does some work if the attribute is requested, and just falls off the 
>>end. What is the proper way to handle this situation? Raise an exception 
>>for other attributes, return None for other attribute lookups, use a 
>>property, or something else? (After writing this up email, I think just 
>>assigning the retval of a method to an attribute in __init__ is probably 
>>better than using __getattr__ in this case.)
> 
> 
> Raise AttributeError when the attribute reference can not be resolved.  
> 
> In this case why not just make fullpath a method?  (changing name to
> get_fullpath?)  I do not see how __getattr__ is buying you much here.
> 

I agree; I'll change it.

> I find __getattr__ most useful for cases where an object is "sitting in
> front" of another object (e.g. proxy, decorator, adapter).  For that
> situation, you want to catch attribute references and redirect them to
> the object that contains the attribute.
> 

These suggestions/associations are helpful. I understand adapter; I have 
to review again what the other design patterns mean.

Thanks for the input.

Rich


More information about the Tutor mailing list