Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86882
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 250
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-12 22:31
文章分类

全部博文(26)

文章存档

2016年(26)

我的朋友

分类: Python/Ruby

2016-11-15 22:18:15


点击(此处)折叠或打开

  1. #!/usr/bin/env python
  2. #_*_ coding:utf-8 _*_
  3. import os,sys
  4. if os.path.isfile('menu_info.txt'):
  5.     pass
  6. else:
  7.     sys.exit("\033[31m没有定义menu_info.txt\033[0m")

  8. usr_dic = {}
  9. with open('menu_info.txt') as f1:
  10.     for i in f1:
  11.         area_dic = {}
  12.         l1 = i.split(':')
  13. # usr_dic[l1[0]] = l1[1]
  14.         l2 = l1[1].strip('\n').split(' ')
  15.         d1 = {}
  16.         for i in l2:
  17.             l3 = i.split('|')
  18. # d1[l3[0]] = l3[1]
  19. # print (d1)
  20.             l4 = l3[1].split(';')
  21.             d2 = {}
  22.             for m in l4:
  23.                 l5 = m.split('*')
  24.                 d2[l5[0]] = l5[1]
  25.             d1[l3[0]] = d2
  26. # print (d1)
  27.         usr_dic[l1[0]] = d1
  28. #print (usr_dic)
  29. while True:
  30.     li_m = []
  31.     for m,n in enumerate(usr_dic,1):
  32.         print (m,n) #打印出城市和序列号
  33.         li_m.append(m)
  34.     city_code = input("\033[32mplease input your right code or 'q'(quit):\033[0m")
  35.     if city_code in str(li_m):
  36.         for m, n in enumerate(usr_dic, 1):
  37.             if m == int(city_code):

  38.                 while True:
  39.                     li_x = []
  40.                     for x,y in enumerate(usr_dic[n],1):
  41.                         print (x,y) #打印出区信息
  42.                         li_x.append(x)
  43.                     res_code = input("\033[32mplease input: your 'area_code' or 'b' or 'q'(b:back q:quit):\033[0m")
  44.                     if res_code in str(li_x):
  45.                         for x,y in enumerate(usr_dic[n],1):
  46.                 # print (x,y,usr_dic[n][y])
  47.                             if res_code == str(x):

  48.                                 while True:
  49.                                     li_u = []
  50.                                     for u,v in enumerate(usr_dic[n][y],1):
  51.                                         print (u,v) #打印出镇的信息
  52.                                         li_u.append(u)
  53.                                     town_code = input("\033[32mplease input: your 'area_code' or 'b' or 'q'(b:back q:quit):\033[0m")
  54.                                     if town_code in str(li_u):
  55. # print (town_code)
  56.                                         for u, v in enumerate(usr_dic[n][y],1):
  57.                                             if u == int(town_code):
  58.                                             # print (u,usr_dic[n][y][v])
  59.                                                 print (usr_dic[n][y][v]) #打印镇的具体地点信息
  60.                                                 sys.exit(0)
  61.                                     elif town_code == 'b':
  62.                                         break
  63.                                     elif town_code == 'q':
  64.                                         sys.exit('\033[32mByeBye\033[0m')
  65.                                     else:
  66.                                         print ('\033[31merror input,please input agin\033[0m')
  67.                     elif res_code == 'b':
  68.                         break
  69.                     elif res_code == 'q':
  70.                         sys.exit('\033[32mByeBye\033[0m')
  71.                     else:
  72.                         print ('\033[31merror input,please input again\033[0m')
  73.     elif city_code == 'q':
  74.         sys.exit('\033[32mByeBye\033[0m')
  75.     else:
  76.         print ("\033[31merror input,please input again\033[0m")


[yn@localhost@../menu]$cat menu_info.txt 
北京:朝阳|三里屯*三里屯医院,三里屯小学;潘家园*潘家园街道办事处,潘家园小学 昌平|沙河*老男孩教育,沙河链家地产;回龙观*回龙观中学,回龙观公园
上海:徐家汇|徐家汇街道*徐家汇福特4s店,徐家汇中学;长桥街道*长桥小学,长桥医院 闵行区|七宝镇*七宝镇中学,如家七宝镇店;马桥镇*马桥医院,马桥小学
深圳:福田|福田街办*福田小学,福田幼儿园;梅林街办*梅林医院,梅林中学 南山区|蛇口*家家顺蛇口店,蛇口办事处;南头*南山小学,南山集团


阅读(1220) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~