Ask coding questions

← Back to all posts
3
NameError problem
jasonpark (2)

The output says that I have a NameError: name 'month' is not defined. But I'm pretty sure it is returned from the function "get_filters()". What am I doing wrong here? Thanks in advance to all that help.

Commentshotnewtop
1
Neil_Chaudhury (9)

So the first error is a no module named pandas error. You can fix this be creating a file called requirements.txt and putting pandas in there. I apologize but I may not be able to help you much further with this, as my computer is weak and is having a hard time running your program

1
jasonpark (2)

@Neil_Chaudhury I appreciate your help! thank you!

1
leon332157 (55)

@jasonpark https://repl.it/@leon332157/ObedientBasicMicrobsd

Use it with out a main function and add a global keyword will make the variable global accessible.

1
jasonpark (2)

@leon332157 how do i make the variable global when it is produced in a function from a user input? also, when the function returns a variable, does that not make it global?

1
jasonpark (2)

@leon332157 I would take out the main function but I need the program to be able to restart under the while loop in the main function.

1
leon332157 (55)

@jasonpark So split the question into two parts, first, if you want to make a variable from a function global, you can use the global keyword at the start of the function, like
def fun():
.global name
.name=input('name')

and the second part is, the value functions returns can be the same name as your variable outside of the function, but returning the variable inside of the function will not change the variable outside of the function unless the variable is a global variable, when a variable is global, you can change it in the function, no need for return.

1
jasonpark (2)

@leon332157 I see! Thank you very much!

1
jasonpark (2)


This is the error I get when running.