On Jun 25, 8:21 pm, Marius Gedminas <[EMAIL PROTECTED]> wrote: > On Jun 24, 2:12 pm, Bjoern Schliessmann <usenet- > > [EMAIL PROTECTED]> 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.
Or possibly try: do_func = elmt.some_func except AttributeError: do_stuff() else: do_func() (internally hasattr is doing that anyway). Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list