Collections of non-arbitrary objects ?
Marius Gedminas
mgedmin at gmail.com
Mon Jun 25 14:21:11 EDT 2007
On Jun 24, 2:12 pm, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n... at spamgourmet.com> wrote:
> 7stud wrote:
> > if hasattr(elmt, some_func):
> > elmt.some_func()
>
> Personally, I prefer
>
> try:
> elmt.some_func()
> except AttributeError:
> # do stuff
That also hides attribute errors that occur within some_func. I think
I'd rather know when elmt has an implementation of some_func that is
buggy. Thus I prefer the hasattr version.
More information about the Python-list
mailing list