On Apr 26, 2013 10:45 PM, "Devin Jeanpierre" <jeanpierreda@gmail.com> wrote:
>
> Code:
> class A:
> @property
> def text(self):
> return self.foo
>
> Behavior:
> >>> hasattr(A(), 'text')
> False
>
> Actually, this is absolutely correct. "A().y" does not give a result
> -- in fact, it raises AttributeError. Behavior wise, this is exactly
> what it means for an attribute to not exist.
>
What about using inspect.getattr_static()?
def hasattr_static(obj, name):
try:
getattr_static(obj, name)
except AttributeError:
return False
else:
return True
-eric