Exception Attributes

AttributeError.name — exception attribute

Inspect the attribute name involved in a failed lookup or assignment. The field is optional; a custom AttributeError may not include it. This can be more reliable than parsing the diagnostic message.

Formal Syntax & Structure

python syntaxpython
error.name

Return Value

str | None

Attempted attribute name.

Working Example

Example Snippetpython
class Record:    passrecord = Record()try:    record.quantityexcept AttributeError as error:    print(error.name)
Python Reference