I am calling a function from a second script but the variable from the first script is not recognized.
script1
selection = int(raw_input("Enter Selection: "))
if selection == 1:
import script2
script2.dosomething()
script2
def dosomething():
while selection == 1:
......
......
It displays "NameError: global name 'selection' is not defined"
Is it something to do with global variables?
selectionwas defined inscript2's scope, so it gives you aNameError. There are a couple ways to getselectionintoscript2's scope: pass it in as a variable, definescript1andscript2in the same file withscript1in the same or higher scope, or defineselectionasglobal. See stackoverflow.com/questions/291978/…selectionis global in this case.globalkeyword? It isn'tglobal.