其他分享
首页 > 其他分享> > Day19作业及默写

Day19作业及默写

作者:互联网

三级菜单

menu = {
    '北京': {
        '海淀': {
            '五道口': {
                'soho': {},
                '网易': {},
                'google': {}
            },
            '中关村': {
                '爱奇艺': {},
                '汽车之家': {},
                'youku': {},
            },
            '上地': {
                '百度': {},
            },
        },
        '昌平': {
            '沙河': {
                '老男孩': {},
                '北航': {},
            },
            '天通苑': {},
            '回龙观': {},
        },
        '朝阳': {},
        '东城': {},
    },
    '上海': {
        '闵行': {
            "人民广场": {
                '炸鸡店': {}
            }
        },
        '闸北': {
            '火车战': {
                '携程': {}
            }
        },
        '浦东': {},
    },
    '山东': {},
}
# l = [menu]
# while l:
#     for k in l[-1]:
#         print(k)
#     key = input('>>>')
#     if key.upper() == 'B':
#         l.pop()
#     elif key.upper() == 'Q':
#         l.clear()
#     elif l[-1].get(key):
#         l.append(l[-1][key])

计算文件夹大小的例子

D:\s20\

D:\s20\day16

D:\s20\day16\day16

import os
def get_size(path):
    size = 0
    l = [path]
    while l:
        path = l.pop()
        lst = os.listdir(path)
        for name in lst:
            son_path = os.path.join(path,name)
            if os.path.isfile(son_path):
                size += os.path.getsize(son_path)
            else:
                l.append(son_path)
    return size

size = get_size(r'D:\s14\算法')
print(size)

标签:作业,son,s20,默写,key,path,os,Day19,size
来源: https://www.cnblogs.com/meilong/p/Day19zuo-ye-ji-mo-xie.html