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
🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 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.
🌐
W3Schools
w3schools.com › python › ref_exception_nameerror.asp
Python NameError Exception
Python Examples Python Compiler ... Plan Python Interview Q&A Python Training ... The NameError exception occurs if you use a variable that is not defined....
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 - 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
Keep getting Nameerror: name error is not defined - Python - Code with Mosh Forum
Hi guys, I’m 40 minutes in to learning python with Mosh and I keep on getting this error when I run my script for the weight converter excercise: weight = int(input('Weight: ‘)) unit = input(’(K)g or (L)bs: ') # type… More on forum.codewithmosh.com
🌐 forum.codewithmosh.com
1
November 15, 2021
🌐
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

🌐
GeeksforGeeks
geeksforgeeks.org › python › handling-nameerror-exception-in-python
Handling NameError Exception in Python - GeeksforGeeks
July 1, 2026 - A NameError occurs when Python cannot find a variable, function, or identifier that is being referenced in the program.
🌐
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
🌐
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.
🌐
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.
🌐
Carleton University
cs.carleton.edu › cs_comps › 1213 › pylearn › final_results › encyclopedia › nameError.html
Error Encyclopedia | Name Error
NameError exceptions in Python are generally raised when you try to access a variable that you have not defined properly. This could happen because the variable truly hasn't been defined yet, or perhaps only be due to a slight typo.
🌐
Quora
quora.com › How-do-I-solve-the-problem-of-NameError-not-a-defined-name-in-Python-3-8
How to solve the problem of 'NameError' not a defined name in Python 3.8 - Quora
Answer (1 of 2): The Error means you are using a name that you have not already defined. Without seeing your code it is impossible to tell you exactly what the problem is, but a simple code example that generates the error: [code]my_name = 'Tony' print(my_Name) [/code]As you can see the error o...
🌐
Facebook
facebook.com › groups › 366190054572553 › posts › 1539182237273323
What is causing the NameError in Python code?
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
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
Edit: Thank you everyone who helped me understand this error. By default, Geany and VSCode were using Python2 as my interpreter. Changing it to Python3 fixed the problem.
🌐
Rollbar
rollbar.com › home › how to solve an undefined variable nameerror in python
How to Solve an Undefined Variable NameError in Python
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.
Published: May 16, 2023
🌐
Facebook
facebook.com › groups › cs50 › posts › 2465169576963406
What causes a NameError in Python code?
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
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.
🌐
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.
🌐
Code with Mosh
forum.codewithmosh.com › python
Keep getting Nameerror: name error is not defined - Python - Code with Mosh Forum
November 15, 2021 - Hi guys, I’m 40 minutes in to learning python with Mosh and I keep on getting this error when I run my script for the weight converter excercise: weight = int(input('Weight: ‘)) unit = input(’(K)g or (L)bs: ') # type: kgs if unit.upper() == ‘K’: converted = weight / 0.45 print("Weight in Lbs: " + str(converted)) else: converted = weight * 0.45 print('Weight in Kgs: ’ + str(converted)) Run: Weight: 80 (K)g or (L)bs: k Traceback (most recent call last): File “/Users/Oli/PycharmProje...
🌐
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, constentType, question, answer): self.contentName = contentName self.constentType = constentType self.question = question self.answer = answer def __str__(self): return "Question : ...
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 3e › chapter1.html
Chapter 1 - Python Basics, Automate the Boring Stuff with Python, 3rd Ed
In this book, the >>> prompt indicates a response to the Python interactive shell and the > prompt indicates a response to a program running the input('>') call. My choice of '>' was arbitrary; you can use any prompt you want or no prompt at all. You can think of the input() function call as an expression that evaluates to whatever string the user typed. If the user entered 'Al', the assignment statement would effectively be my_name = 'Al'. If you call input() and see an error message, like NameError: name 'Al' is not defined, the problem is that you’re running the code with Python 2 instead of Python 3.
🌐
Python documentation
docs.python.org › 3 › tutorial › errors.html
8. Errors and Exceptions — Python 3.14.7 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