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 15, 2025 - There are several standard exceptions in Python and NameError is one among them. NameError is raised when the identifier being accessed is not defined in the local or global scope.
🌐
Python
docs.python.org › 3 › library › exceptions.html
Built-in Exceptions — Python 3.14.3 documentation
Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable. This is a subclass of NameError.
Discussions

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
"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: name 'turn' is not defined. Any ideas why and how to fix this? def game(): ... More on discuss.python.org
🌐 discuss.python.org
9
0
October 27, 2021
python - NameError: name 'i' is not defined - Why does this happen? - Stack Overflow
I am making a rather simple wordle clone for my class. It functions exactly the same as wordle, just in a CLI. However, I am getting a weird error when testing. When executed, python returns Traceb... More on stackoverflow.com
🌐 stackoverflow.com
Name error : 'name' is not defined
The code below should perform the letter counter for a given language, but it gives the message: NameError: name ‘dutch’ is not defined. What I try to do is put the language in the function argument and then look for the file that has the name language.txt and run the program on it. More on discuss.python.org
🌐 discuss.python.org
1
0
April 1, 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 'NameError: name 'x' is not defined' in Python | Rollbar
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 'NameError: name 'x' is not defined' in Python | Rollbar
🌐
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

🌐
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 ...
Find elsewhere
🌐
W3Schools
w3schools.com › python › ref_exception_nameerror.asp
Python NameError Exception
Python Examples Python Compiler ... Python Certificate Python Training ... The NameError exception occurs if you use a variable that is not defined....
🌐
Rollbar
rollbar.com › home › how to solve an undefined variable nameerror in python
How to Solve 'NameError: name 'x' is not defined' in Python | Rollbar
March 17, 2025 - In Python, a NameError: name 'x' is not defined error is raised when the program attempts to access or use a variable that has not been defined or assigned a value.
🌐
Real Python
realpython.com › ref › builtin-exceptions › nameerror
NameError | Python’s Built-in Exceptions – Real Python
NameError is a built-in exception that occurs when you try to use a variable or function name that isn’t defined yet.
🌐
Python documentation
docs.python.org › 3 › tutorial › errors.html
8. Errors and Exceptions — Python 3.14.3 documentation
>>> 10 * (1/0) Traceback (most recent call last): File "<stdin>", line 1, in <module> 10 * (1/0) ~^~ ZeroDivisionError: division by zero >>> 4 + spam*3 Traceback (most recent call last): File "<stdin>", line 1, in <module> 4 + spam*3 ^^^^ NameError: name 'spam' is not defined >>> '2' + 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> '2' + 2 ~~~~^~~ TypeError: can only concatenate str (not "int") to str
🌐
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 - A NameError is raised when you try to use a variable or a function name that is not valid. In Python, code runs from top to bottom. This means that you cannot declare a variable after you try to use it in your code.
🌐
Python.org
discuss.python.org › python help
Name error : 'name' is not defined - Python Help - Discussions on Python.org
April 1, 2022 - The code below should perform the letter counter for a given language, but it gives the message: NameError: name ‘dutch’ is not defined. What I try to do is put the language in the function argument and then look for the file that has the name language.txt and run the program on it.
🌐
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 - The resulting error was this: NameError: name 'math' is not defined. This happened because the interpreter did not recognize the math keyword. Along with other math methods in Python, we must first import the math module to use it.
🌐
Quora
quora.com › How-do-I-rectify-a-name-not-defined-error-in-Python
How to rectify a “name not defined” error in Python - Quora
Answer (1 of 2): Name not defined error comes, when you are using a variable that is not defined or declared previously. It is generally in the case when you do a typo. In my cases, I make the mistake of type arr —- as ar and then I get name ...
🌐
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
🌐
Saturn Cloud
saturncloud.io › blog › how-to-fix-the-nameerror-in-jupyter-notebook
How to Fix the NameError in Jupyter Notebook | Saturn Cloud Blog
December 2, 2023 - The solutions to fix this error include defining the variable, checking for typos, importing the module, renaming the variable and minding the cell’s order. By following these solutions, you can fix the NameError and continue working on your Jupyter Notebook project without interruptions.
🌐
TechGeekBuzz
techgeekbuzz.com › blog › python-nameerror-name-is-not-defined-solution
Python NameError: name is not defined Solution
NameError occurs when we use an invalid variable or function in a program . The Python interpreter executes the code from top to bottom. Hence, you have to declare a variable before using it. If you use it without declaration, you get NameError.
🌐
Airbrake
blog.airbrake.io › blog › python › python-nameerror
Python Exception Handling - NameError
July 13, 2022 - Just as with many other programming languages, Python source code (typically found in .py files) is initially compiled into bytecode, which is a low level representation of source code that can be executed by a virtual machine via the CPython interpreter. Part of this process involves loading local or global objects into the callstack. However, when Python attempts to load an object that doesn't exist elsewhere in the callstack it will forcefully raise a NameError indicating as much.
🌐
Medium
medium.com › @rayancrazer › name-error-in-python-69393dbeec04
Unlocking the Mystery of NameError in Python: How to Fix It
November 24, 2024 - 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
How can I resolve NameError? - Python Help - Discussions on Python.org
May 27, 2020 - Hello everyone~ Acctually I don’t know how to make the code of program. But I’m intersted in Phython and I’m wathching Youtube and following the instruction. And I encountered some unexpected problem. This is no problem import openpyxl class Conversation: def __init__(self, contentName, ...