Exception Attributes
NameError.name — exception attribute
Inspect the unqualified identifier associated with a name lookup failure. The interpreter often populates it, but custom errors and some subclasses can leave it unset. Avoid extracting the name from a human-facing error string.
Formal Syntax & Structure
python syntaxpython
error.nameReturn Value
str | None
Name attached to the failure.
Working Example
Example Snippetpython
try: print(bytemind_unbound_demo_28)except NameError as error: print(error.name)