Thanks for the clarification guys. That is truly horrific :)
Sorry not to have tested my suggestion first.
Michael
On Thursday, September 4, 2014 5:20:18 PM UTC+1, Zachary McCord wrote:
>
> I simply didn't believe it at first, but sure enough, in python 2.7:
>
> >>> class Bomb(object):
> ...
I simply didn't believe it at first, but sure enough, in python 2.7:
>>> class Bomb(object):
... def __getattr__(self, id):
... assert False
...
>>> bomb = Bomb()
>>> bomb.foo
Traceback (most recent call last):
File "", line 1, in
File "", line 3, in __getattr__
Assertion
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
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
unfortunately hasattr eats even more exceptions than AttributeError.
--
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 django-users+unsubscr...@googlegroups.com.
T
Hi,
I love Django, it has been enormously useful to a new comer to web dev like
me.
One minor issue I've just had is that I've struggled to figure out an issue
with my code because an AttributeError I was generating in my media
property on my custom widget was being silently swallowed by:
6 matches
Mail list logo