Ed Leafe wrote:
> On Jun 11, 2008, at 3:20 PM, Nate Lowrie wrote:
> 
>>      def _getShowColumnLabels(self):
>> -            return self._showColumnLabels
>> +            if hasattr(self, "_showColumnLabels"):
>> +                    v = self._showColumnLabels
>> +            else:
>> +                    v = self._showColumnLabels = True
>> +            return v
> 
>       This construction is to be avoided. It is best to either: a)  
> initialize the underlying attribute in the __init__() method, or b)  
> use a try/except. This should only fail once and could possibly be  
> called unlimited times, and hasattr() tests add up.

Forget what I just said, you are right we shouldn't make that test each 
time. I prefer:

try:
   v = self._showColumnLabels
except AttributeError:
   v = self._showColumnLabels = True
return v

...because it encapsulates the attribute inside the property definition 
instead of inside the class definition.

Paul


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to