Python 包含文件夹路径转字典

def dictizeString(string, value, dictionary):
    while string.startswith('/'):
        string = string[1:]
    parts = string.split('/', 1)
    if len(parts) > 1:
        branch = dictionary.setdefault(parts[0], {})
        #branch = dictionary.setdefault(parts[0], value)
        #dictizeString(parts[1], branch)
        dictizeString(parts[1], value, branch)
    else:
        if dictionary.has_key(parts[0]):
             dictionary[parts[0]] += 1
        else:
             dictionary[parts[0]] = value


office = {}
for k, v in worker.items():
    dictizeString(k, v, office)


print(office)

上一篇:SCCM2012 R2实战系列之十一:解决OSD分发Windows7 系统盘盘符为’D’问题


下一篇:QtCreator 获取Git版本信息