Collections of non-arbitrary objects ?

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Sun Jun 24 07:12:16 EDT 2007


7stud wrote:
> On Jun 23, 11:45 am, walterbyrd <walterb... at iname.com> wrote:

>> Suppose you are sequentially processing a list with a routine
>> that expects every item to be of a certain type. Something in the
>> list that doesn't conform to the type could give you unexpected
>> results, maybe crash your application.
>>
> 
> if hasattr(elmt, some_func):
>    elmt.some_func()

Personally, I prefer

try:
    elmt.some_func()
except AttributeError:
    # do stuff

Regards,


Björn

-- 
BOFH excuse #130:

new management




More information about the Python-list mailing list