Am trying this small piece of code which can be alternative for switch. But i get weired Error.
def main(x):
x = x.split(' ')
return {'Function1' : Function1(x),
'Function2' : Function2(x),
}[x[0]]
def Function1(x):
var1 = x[0]
var2 = x[1]
def Function2(x):
print x[0]
main("Function1 10")
Now the above code work fine. Problem is if i pass Function2 as key without any arguments to main function it automatically goes into Function1 and throws list out of range error.
main("Function2")
Thanks in Advance.
Function2you did not define any variablexbut you are accessing its 1st element