believe it or not, hasattr is the same as:
try:
getattr(obj, name)
return True
except: # yikes! naked except!
return False
https://docs.python.org/2/library/functions.html#hasattr
So, excepting AttributeError will at least narrow down the error slightly,
rather than hasattr accepting _any_ exception.
On Thu, Sep 4, 2014 at 4:29 AM, Michael Jones <[email protected]>
wrote:
> Hi,
>
> Thanks for the reply, but I'm not sure I follow. I was hoping that the
> following might work:
>
> if hasattr(sup_cls, 'media'):
> base = sup_cls.media
> else:
> base = Media()
>
> Would that swallow additional exceptions?
>
> Cheers,
> Michael
>
>
> On Wednesday, September 3, 2014 10:45:22 PM UTC+1, Collin Anderson wrote:
>>
>> unfortunately hasattr eats even more exceptions than AttributeError.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/K26vVvKWnTs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9db016be-bc63-44b4-934c-7b2c64ae9863%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9db016be-bc63-44b4-934c-7b2c64ae9863%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAFO84S6fAYN6Erv7W_RCPNkjUagEPrWA_sZBaV_mUjVM4k6Gcw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.