[Tutor] ftp program

Lloyd Kvam pythonTutor at venix.com
Sat Aug 28 17:36:28 CEST 2004

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 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.


Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-653-8139
fax:	320-210-3409 (changed Aug 26, 2004)

More information about the Tutor mailing list