Chapters
Python114 chapters

ReferenceException types

AttributeError

No such attribute or method on that object.

Signature

AttributeError(message)

Returns

Often the sign of a typo, or of a value being None when you did not expect it.

Example

Python
try:
    "abc".push("d")
except AttributeError:
    print("strings have no push method")

value = None
try:
    value.strip()
except AttributeError:
    print("the value was None")

Output

strings have no push method
the value was None

See also