hasattr() vs essayez-à l'exception du bloc pour faire face à l'absence d'attributs

if hasattr(obj, 'attribute'):
    # do somthing

vs

try:
    # access obj.attribute
except AttributeError, e:
    # deal with AttributeError

Qui devrait être préféré et pourquoi?

InformationsquelleAutor Imran | 2009-05-24