Theerasak Photha a écrit : > On 10/11/06, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > > > Now the real question : what if the object is not an instance of any of > > the types, but still support the expected interface ? > > Perhaps: > > try: > for attribute in ['foo', 'bar', '__baz__']: > getattr(mystery_object, '__%s__' % attribute) > except AttributeError: > # Do sumthin bout it
Isn't this a case of useless overcomplexification ? Since you end up raising an exception, why not just assume the object is ok and let Python raise the exception for you if it is not ? From the client code POV, it doesn't make much difference !-) > Is it wrong to 're-raise' an exception with application-specific > details within an except clause? Nope - as long as you provide more details (or more helpful details) *and* do not loose/mask/whatever useful infos from the original exception. -- http://mail.python.org/mailman/listinfo/python-list