all Python 3Exceptionsexception
AttributeError
built-in exceptions
Raised when an attribute or method that the object does not have is accessed.
Syntax
raise AttributeError('сообщение')
Most student AttributeErrors are really None in disguise: in-place methods such as list.sort(), list.append() and random.shuffle() return None, so after lst = lst.sort() the very next call dies with "'NoneType' object has no attribute ...". Read the message to the end — it names both the object's type and the attribute, and since 3.10 the interpreter also suggests a close match when you merely mistyped.
Examples
x = 42
x.upper() # AttributeError: 'int' has no 'upper'
class A: pass
A().run() # AttributeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy