Search code examples
pythonattributeshasattr

hasattr with functions


How to check attr existence in function or method with hasattr (or without)? When I try to check it is False in any way:

>>> def f():
        at = True


>>> hasattr(f, 'at')
False
>>> hasattr(f(), 'at')
False

Solution

  • Local variables are not attributes. You cannot use any *attr() to frob them.