Hello,
I found this code in a thread from about 18 months ago in a post by 'woooee' -
def func_1():
print " func_1 test"
def func_2():
print " func_2 test"
def func_3():
print " func_3 test"
def func_4():
print " func_4 test"
##----------------------------------------------------------------
## dictionary = list of function to call and menu choice to print
menu_d = { 1:['func_1()', '1)Load'],
2:['func_2()', '2)Save'],
3:['func_3()', '3)Add Phone Number'],
4:['func_4()', '4)View Phone Number'],
5:["", "5)Exit"]}
choice = 0
while choice != 5:
print "\nSelect an Option\n"
for j in range(1, 6):
print menu_d[j][1] ## print list's element #1 for key=j
choice = int(raw_input( "Enter choice, 1-5 " ))
if choice in menu_d:
dict_list = menu_d[choice]
eval(dict_list[0])
## eval(menu_d[choice][0]) will also work
print "\nend of program"
Options 1-4 work fine. However, when I choose option 5 I get this -
Traceback (most recent call last);
File "/home/......... .py", line 101, in <module>
eval(dict_list[0])
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
I've checked and double checked for typo(s). I'm afraid I've not understood the answers I've found from Google!
Any pointers much appreciated.
Tim