🎓 Free Capstone Projects with Full Documentation, ER Diagrams & Source Code — Updated Weekly for 2026
👨‍💻 Free Source Code & Capstone Projects for Developers

Frequently Asked Questions

What is the difference between NameError and UnboundLocalError?
NameError means Python looked in all reachable scopes and never found the name. UnboundLocalError means Python found the name as a local variable but you tried to use it before it was assigned. Both are about names, but UnboundLocalError happens specifically inside functions when you read a local before writing it.
I imported the module, why is the alias not defined?
You probably did import numpy but then used np.array(...). Either change the import to import numpy as np, or use the full name numpy.array(...). The alias only exists if you create it with as.
Why does "name 'display' is not defined" happen?
display() is a built-in inside Jupyter notebooks (provided by IPython), but it does not exist in regular Python scripts. To use it outside Jupyter, explicitly import: from IPython.display import display. Better yet, replace it with print() or repr() if you do not need the rich notebook output.
Why does "name 'raw_input' is not defined" happen?
You are running Python 3 code that uses raw_input() from Python 2. In Python 3, raw_input was renamed to input. Replace every raw_input(...) with input(...). The old input() from Python 2 (which evaluated input as code) is gone — Python 3's input() always returns a string.
Why does "name '__file__' is not defined" happen in Jupyter?
The __file__ attribute exists when Python imports a module from a file — it holds that file's path. Jupyter cells are not loaded from a file path, so __file__ does not exist in notebook scope. For notebooks, use os.getcwd() to get the working directory, or hardcode the path you need.
How do I prevent NameError?
(1) Use a linter (pyflakes, ruff, pylint) — they catch undefined names before runtime. (2) Use an IDE with import suggestions (VS Code Python extension, PyCharm). (3) Run mypy or pyright in CI — type checkers catch most undefined-name bugs. (4) For notebooks, restart the kernel and run all cells top-to-bottom occasionally to ensure no hidden state.
How often is this NameError reference updated?
New posts are added as we hit them in real projects. Existing posts are revised when major Python versions ship changes. Last refreshed: May 2026.