zoukankan      html  css  js  c++  java
  • 三级菜单读取文件版

    ext_flag = False
    # file = open("menu",'r',encoding='utf-8')    # 打开3级菜单文本文件
    # f = file.read()
    
    with open('menu','r',encoding='utf-8') as aff:  # 打开3级菜单文本文件
        f= aff.read()
    for line in f:          # 读取文件中每行信息
        file_str = str(f)    # 将每行信息转成字符串格式
    now_layers = eval(file_str)    # 字符串转成字典格式
    last_layers = [now_layers]      #把字典转成列表
    # print(now_layers)
    # print(last_layers)
    
    while not ext_flag:
        for key in now_layers:
            print(key)
        choice = input('>>:').strip()
        if len(choice) == 0: continue
        if choice in now_layers:
            last_layers.append(now_layers)
            now_layers =now_layers[choice]
        if choice =='b':
            if last_layers:
                now_layers=last_layers[-1]
                last_layers.pop()
        if choice == 'q':
            ext_flag = True

    menu文件内容

    {
    '浙江':{
    '杭州':{
    '西湖':{
    '西溪',
    '三墩'},
    '滨江':{'滨和':{}, '高新':{}}
    },
    '丽水':{
    '龙泉':{'宝剑':{}, '瓷器':{}},
    '青田':{'石雕':{}, '华侨':{}},
    '缙云':{'烧饼':{}, '木雕':{}},
    },
    },
    '山东':{
    '烟台':{'大海':{}, '日照':{}},
    '青岛':{'平度':{}, '黄岛':{}},
    '东营':{'利津', '垦利'}
    },
    '广东':{
    '深圳':{'南山':{}, '福田':{}},
    '梅州':{'五华':{}, '兴宁':{}},
    '佛山':{'三水':{}, '桂城':{}}
    }
    }

  • 相关阅读:
    任务墙(6月3日)
    燃尽图(6月3日)
    6.1-6.2小结
    5月28日任务进展
    个人感悟
    代码评审
    如何用ZBrush确定头部五官的位置
    ZBrush中的纹理-水手该怎样进行绘制
    怎样对ZBrush中的材料进行渲染和着色
    快速熟悉Zbrush中的四种裁切笔刷
  • 原文地址:https://www.cnblogs.com/jack2017/p/7521344.html
Copyright © 2011-2022 走看看