Paul McNett wrote:
> Ricardo Aráoz wrote:
>> Paul McNett wrote:
>>> Actually, you'd be better off checking that you have an object first:
>>>
>>> lbl = getattr(self, curlabel, None)
>>> if lbl:
>>> lbl.Caption = "somestr"
>>>
>>> HTH
>>>
>> How un-pythonic! Use exceptions!
>
> Ok:
>
> try:
> lbl = getattr(self, curlabel)
> except AttributeError:
> lbl = None
>
> if lbl:
> lbl.Caption = "somestr"
>
> Please explain why those 6 lines are better than my original 3.
>
try : lbl = getattr(self, curlabel)
except: # do other stuff your original code won't do
finally : lbl.Caption = "somestr"
I guess those three lines do what your original 3 do, but faster.
Or if you accept an Xtra line :
try :
lbl = getattr(self, curlabel)
lbl.Caption = "somestr"
except : pass # or some other line with xtra functionality
BTW didn't mean to pick a fight, though re-reading my post you might
have interpreted it that way, sorry if that was the case.
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]