Built-in Exceptions

NameError — exception class

A name could not be resolved in the applicable scopes. Check the spelling and whether the variable was bound before use. UnboundLocalError is a more specific name-resolution failure. The name attribute can report the unresolved identifier. Catch NameError when this category is the recovery boundary; do not rely on the exact human-readable message.

Formal Syntax & Structure

python syntaxpython
NameError

Return Value

type

The class object NameError; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
try:    eval("missing_bytemind_name_27", {})except NameError as error:    print(type(error).__name__)
Python Reference