Python 三级菜单练习3.0

a = open('F:\PycharmProjects\study\city_dict1.txt', 'r', encoding='utf8')
date = a.read()
a.close()

menu0 = eval(date)
menu1 = []
menu2 = menu0
while True:
# menu1 = menu1.append(menu0)
for key in menu0:
print(key)
choice = input('>>>:').strip()
if len(choice) == 0: continue
elif choice in menu0:
menu1.append(menu0)
menu0 = menu0[choice]
elif choice == 'q': break
elif choice == 'b':
menu0 = menu1.pop()
elif '+' in choice and len(choice) > 1:
menu0[choice[1:]] = {}
elif '-' in choice and len(choice) > 1:
del menu0[choice[1:]]
else: print('查无此项')

b = open('F:\PycharmProjects\study\city_dict1.txt', 'w', encoding='utf-8')
b.write(str(menu2))
b.close()
posted @ 2018-10-05 21:06  david2018  阅读(132)  评论(0编辑  收藏  举报