python
type_error
official
true
NameError
ID: python/nameerror
80%Fix Rate
95%Confidence
0Evidence
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
A local or global name is not defined. Usually a typo in the variable name, or referencing a variable before assignment.
genericOfficial Documentation
https://docs.python.org/3/library/exceptions.htmlWorkarounds
-
90% success Check spelling of the variable/function name
Use IDE autocomplete; ensure the variable is defined before use
-
90% success Check import statements and ensure the name is in scope
Verify 'import module' or 'from module import name' is executed
Dead Ends
Common approaches that don't work:
-
Adding a global declaration without understanding the scope
80% fail
May create unintended side effects across modules