nameerror

Unexpected NameError in Python without syntax error

Unexpected NameError in Python without syntax error Question: I’m trying to write in Visual Studio Code for Linux a simple roll dice program, but for some reason I have an unexpected NameError that makes me mad. This is my code: from random import randint class Dice: def __init__(self, sides): self.sides = sides def roll(self): play …

Total answers: 2

Visual Studio Code: FileNotFoundError. Execute in File Dir broken, and unable to access file's absolute path

Visual Studio Code: FileNotFoundError. Execute in File Dir broken, and unable to access file's absolute path Question: I am trying to open a CSV file without using its absolute path, but I cannot access it because my files are located in /Users/foo/Machine Learning/Multiple Linear Regression/, which is a child of my working directory /Users/foo/Machine Learning/Machine …

Total answers: 1

Python: Passing function as parameter to a child process with Pool.map

Python: Passing function as parameter to a child process with Pool.map Question: I want to execute the function func using a multiprocessing.Pool. func takes an input, which is a tuple of two parameters (list, sorting_function). Then the sorting function is to be executed with the list as input. This however throws an Error: NameError: name …

Total answers: 2

Why do the if statements work, but NOT the else statements?

Why do the if statements work, but NOT the else statements? Question: All if statements work, but the else statements in the first two if/else blocks return the following error? Can someone please tell me why this is? Traceback (most recent call last): File "main.py", line 36, in <module> if swim_or_wait.lower() == "wait": NameError: name …

Total answers: 2

`eval('bar')` causes a `NameError`, but `print(bar); eval('bar')` doesn't

`eval('bar')` causes a `NameError`, but `print(bar); eval('bar')` doesn't Question: The following code 1 def foo(): 2 def bar(): 3 return ‘blah’ 4 def baz(): 5 eval(‘bar’) 6 baz() 7 foo() causes a NameError — the entire error message is Traceback (most recent call last): File "main.py", line 7, in <module> foo() File "main.py", line 6, …

Total answers: 1

Having trouble with def functions

Having trouble with def functions Question: I have been taking this class for a bit with python for a bit and I have stumbled into a problem where any time I try to "def" a function, it says that it is not defined, I have no idea what I am doing wrong and this has …

Total answers: 2

NameError: class is not defined when overriding a class in python

NameError: class is not defined when overriding a class in python Question: Why can’t python seem to find the InterfaceWithNoMenu class class Settings(Screen): class SettingsWithNoMenu(kivy.uix.settings.SettingsWithNoMenu): def __init__(self, *args, **kwargs): self.interface_cls = InterfaceWithNoMenu kivy.uix.settings.SettingsWithNoMenu.__init__( self, *args, **kwargs ) class InterfaceWithNoMenu(kivy.uix.settings.ContentPanel): def add_widget(self, widget): if self.container is not None and len(self.container.children) > 0: raise Exception( ‘ContentNoMenu cannot …

Total answers: 2

Why is my return function not allowing me to call the code

Why is my return function not allowing me to call the code Question: I was creating an if-else loop based on the type of variable, to either convert a list of numbers to kilograms, or simply one number, and for some reason I cannot call the variable I created into my main() function. I am …

Total answers: 2

List not defined in a function in Python

List not defined in a function in Python Question: I am working on one of my first codes (Tic Tac Toe), and I cannot figure out why I’m getting a name error. First I have a list (board). Then I have a function (possible_victory_for() ) that I define. It is supposed to to something with …

Total answers: 1