generated from xinetzone/sphinx-demo
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuxinwei
committed
Sep 19, 2024
1 parent
b3de65b
commit 3b82823
Showing
4 changed files
with
201 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Bunch(dict): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.__dict__ = self # 这意味着 Bunch 类的实例将具有与字典相同的行为,可以使用点符号访问和修改其键值对 | ||
for k, v in self.__dict__.items(): | ||
if isinstance(v, dict): | ||
self.__dict__[k] = Bunch(**v) # 支持嵌套结构 | ||
|
||
def merge(self, other): | ||
"""提供递归合并功能""" | ||
for k, v in other.items(): | ||
if k not in self: | ||
self[k] = other[k] | ||
else: | ||
if not isinstance(self[k], dict) and not isinstance(v, dict): | ||
self[k] = v | ||
elif isinstance(self[k], dict) and isinstance(v, dict): | ||
self[k].update(v) | ||
else: | ||
raise TypeError(f"{other}不支持合并") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[a] | ||
a.b = "d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters