Define the class before you use it:

class Something:
    def out(self):
        print("it works")

s = Something()
s.out()

You need to pass self as the first argument to all instance methods.

Answer from Blender on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › handling-nameerror-exception-in-python
Handling NameError Exception in Python - GeeksforGeeks
July 1, 2026 - ERROR! Traceback (most recent call last): File "<main.py>", line 1, in <module> NameError: name 'city' is not defined · Explanation: city is accessed before its assignment statement is executed, so Python cannot find the variable.
🌐
OpenPython
openpython.org › home › articles › fix python nameerror: 'name is not defined' (step-by-step)
Fix Python NameError: 'Name Is Not Defined' (Step-by-Step) | OpenPython
May 30, 2026 - A NameError happens when you use a name that Python cannot find in the current scope. The three most common fixes: define the variable before you use it, correct the typo, or add the missing import statement.
Discussions

"NameError: name is not defined"... but it is?
So, im making a tic-tac-toe game and im nearly finished i think. im trying to make it so the game can be played more than just once before it ends. So i put it into a def() function… but running it results in NameError: … More on discuss.python.org
🌐 discuss.python.org
9
0
October 27, 2021
python - How to avoid "NameError: name is not defined" when using a class above its definition - Stack Overflow
I have a Python script and I am receiving the following error: Traceback (most recent call last): File "C:\Users\Tim\Desktop\pop-erp\test.py", line 1, in s = Someth... More on stackoverflow.com
🌐 stackoverflow.com
python - What is this NameError and how do I fix it? - Stack Overflow
I am having difficulty understanding the concept in my book. I tried the coding example the book told me to try, but I get this NameError that I do not understand why it is an error. This is my code: More on stackoverflow.com
🌐 stackoverflow.com
NameError: name 'name' is not defined
Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you. I think I have detected some formatting issues with your submission: Python code found in submission text that's not formatted as code. If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting. Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here . More on reddit.com
🌐 r/learnpython
14
11
July 24, 2022
People also ask

How to solve undefined variable in python
To solve the NameError: name 'x' is not defined error in Python, you need to make sure that the variable is properly defined and assigned a value before it is used. The variable should also be referenced correctly, with the correct case and spelling.
🌐
rollbar.com
rollbar.com › home › how to solve an undefined variable nameerror in python
How to Solve an Undefined Variable NameError in Python
What causes undefined variable?
In Python, a variable is not created until a value is assigned to it. If an attempt is made to use a variable before it is defined, a NameError: name 'x' is not defined error is thrown. The error message typically includes the name of the variable that is causing the problem and the line of code where the error occurred.
🌐
rollbar.com
rollbar.com › home › how to solve an undefined variable nameerror in python
How to Solve an Undefined Variable NameError in Python
🌐
Medium
medium.com › @rayancrazer › name-error-in-python-69393dbeec04
Unlocking the Mystery of NameError in Python: How to Fix It
November 24, 2024 - To fix this error, we need to define my_function() before we try to call it. For example: In summary, NameError in Python occurs when you try to use a variable or function name that has not been defined yet or is out of scope.
🌐
Python.org
discuss.python.org › python help
"NameError: name is not defined"... but it is? - Python Help - Discussions on Python.org
October 27, 2021 - So, im making a tic-tac-toe game and im nearly finished i think. im trying to make it so the game can be played more than just once before it ends. So i put it into a def() function… but running it results in NameError: name 'turn' is not defined. Any ideas why and how to fix this? def game(): blanksheet = "|1|2|3|\n|4|5|6|\n|7|8|9|" sheet = blanksheet print(sheet) gone = [] turn = 0 def play(XO,player,listXO): global turn global sheet global listx global listo ...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › python nameerror
Python NameError | How NameError Works in Python with Examples
January 8, 2024 - The NameError can be avoided easily by using the Python Error handling technique or exception handling, which denotes the user about the NameError that is occurring in the block of code without actually throwing an error.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Find elsewhere
🌐
Rollbar
rollbar.com › home › how to solve an undefined variable nameerror in python
How to Solve an Undefined Variable NameError in Python
To solve the NameError: name 'x' is not defined error in Python, you need to make sure that the variable is properly defined and assigned a value before it is used.
Published: May 16, 2023
🌐
Real Python
realpython.com › ref › builtin-exceptions › nameerror
NameError | Python’s Built-in Exceptions – Real Python
You can avoid raising a NameError by making sure everything you reference is defined or imported and accessible in the current scope before you use it.
🌐
Stack Overflow
stackoverflow.com › questions › 73536966 › what-is-this-nameerror-and-how-do-i-fix-it
python - What is this NameError and how do I fix it? - Stack Overflow
CopyFile "/Users/eric/Python ... error. By default, Geany and VSCode were using Python2 as my interpreter. Changing it to Python3 fixed the problem....
🌐
Reddit
reddit.com › r/learnpython › nameerror: name 'name' is not defined
r/learnpython on Reddit: NameError: name 'name' is not defined
July 24, 2022 -

Hello,

I'm new to coding and don't know what I am doing wrong here. I am using VS Code, and below is what I've inputted. Only "john" and "programmer" are highlighted in red font, while the remaining code is either blue, green, or yellow. From my understanding, those phrases are causing the syntax error. Also, it works fine when I run the same code in IDLE Shell.

name = "john"

age = 21

weight = 160.1

occupation = "programmer"

>>>print(name, age, weight, occupation)

---->Traceback (most recent call last):

File "<stdin>", line 1, in <module>

NameError: name 'name' is not defined

🌐
Career Karma
careerkarma.com › blog › python › python nameerror name is not defined solution
Python nameerror name is not defined Solution | Career Karma
December 1, 2023 - Traceback (most recent call last): ... function until later in our program. To fix this error, we can move our function declaration to a place before we use it:...
🌐
Purple Engineer
purpletutor.com › home › understanding code › python nameerror causes solutions and prevention
Python nameerror explained with debugging tips and variable resolution 🐍🔍
March 25, 2026 - To fix a “NameError: name is not defined” in Python, check for spelling mistakes in the variable or function name and ensure it is defined before being referenced. If the name is from another module, verify that the import statement is correct ...
🌐
Embedded Inventor
embeddedinventor.com › home › nameerror: a step by step troubleshooting guide!
NameError: A Step By Step Troubleshooting Guide!
December 27, 2023 - Traceback (most recent call last): File "/home/main.py", line 6, in <module> print(gender) NameError: name 'gender' is not defined · The fix is simple, we make a variable named “gender” and give it a value
🌐
Python Guides
pythonguides.com › nameerror-name-is-not-defined
NameError: Name is Not Defined in Python
September 3, 2025 - This method demonstrates that variables defined inside a function are local and inaccessible outside, so returning them or declaring them globally fixes the issue. Another common cause is calling a function before defining it. # Wrong greet() def greet(): print("Hello from Python") ... You can refer to the screenshot below to see the output. This method shows that functions must be defined before being called in Python to avoid a NameError.
🌐
freeCodeCamp
freecodecamp.org › news › nameerror-name-plot-cases-simple-is-not-defined-how-to-fix-this-python-error
NameError: Name plot_cases_simple is Not Defined – How to Fix this Python Error
June 27, 2022 - Using a Python module without importing the module, and so on. In this section, you'll see how to fix the "NameError: Name is Not Defined" error in Python.
🌐
YouTube
youtube.com › watch
Python NameError — What it is and how to fix it - YouTube
NameError: name '***' is not definedWhat is a NameError in Python? What can you do to fix it? When does it happen?All these questions are answered in this vi...
Published: August 19, 2024
🌐
OpenPython
openpython.org › python-errors › nameerror
Python NameError — What It Is and How to Fix It | OpenPython
Fix Python NameError quickly. Learn about variable scope, undefined names, and common mistakes that cause NameError in Python programs.
🌐
Medium
medium.com › @chifahatim1 › how-to-fix-nameerror-name-is-not-defined-in-python-beginner-guide-2026-5f4a42dae9dd
How to Fix ‘NameError: name is not defined’ in Python — Beginner Guide 2026 | by Chifahatim | Medium
March 18, 2026 - Always define before use! Cause #2 — Typo in variable name (case-sensitive!) Wrong: age = 25 print(Age) # NameError — 'Age' != 'age'p · Fix: match exactly (Python is case-sensitive).
🌐
W3Schools
w3schools.com › python › ref_exception_nameerror.asp
Python NameError Exception
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The NameError exception occurs if you use a variable that is not defined.
🌐
ScienceDirect
sciencedirect.com › science › article › abs › pii › S0950584924001976
Detecting and Explaining Python Name Errors - ScienceDirect
October 11, 2024 - Among many of the issues impacting the reliability of Python projects, NameError is one of the most popular issues that will be thrown if a given name (e.g., of a variable or a method) cannot be correctly interpreted by Python. The corresponding error message will be “name is not defined”. NameError is often considered not too complicated to be fixed by developers, especially when they are able to reproduce and debug the error.