【发布时间】:2021-10-21 10:49:42
【问题描述】:
对于python,是否有任何通用的数据结构来表示所有操作系统中文件系统中的树?
我目前使用字典并以这种方式存储树。
C/
├─ C1
├─ C3/
│ ├─ C31
tree =
{"title": "root",
"child": [
{"title": "C",
"child": [{"title": "C1"
},
{"title": "C3",
"child": [
{"title": "C31"
}
]
}
]
}
]}
但是,这种幼稚的方式缺少很多功能,比如比较两棵树,计算文件数量等。
是否有任何包可以执行这些功能并具有专门处理文件夹和文件树的数据结构?
【问题讨论】:
-
将树实现为嵌套字典的方法:What is the best way to implement nested dictionaries? 我喜欢@Aaron Hall 的回答。
标签: python python-3.x directory directory-structure