222
توضیحات
两个字典的结构差异,嵌套键以点号路径呈现。
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | 222-0.0.4 |
| نام | 222 |
| نسخه کتابخانه | 0.0.4 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | - |
| ایمیل نویسنده | lqxnjk <lqxnjk@qq.com> |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/222/ |
| مجوز | MIT |
# 222
[English](#english) | 中文
两个字典的结构差异,嵌套键以点号路径呈现。
## 安装
```console
pip install 222
```
## 用法
```python
from p222 import apply_diff, dict_diff
left = {"db": {"port": 5432, "host": "a"}, "tags": ["x"], "gone": 1}
right = {"db": {"port": 6543, "host": "a"}, "tags": ["y"], "new": 2}
dict_diff(left, right)
# {'db.port': ('changed', 5432, 6543),
# 'gone': ('removed', 1, None),
# 'new': ('added', None, 2),
# 'tags': ('changed', ['x'], ['y'])}
apply_diff(left, dict_diff(left, right)) == right # True
```
## 说明
包名以数字开头,导入名是 `p222`。嵌套 dict 递归比较,变化落在 `db.pool.size` 这样的路径上,而不是整棵子树被替换。`apply_diff` 可反向应用,满足 `apply_diff(left, dict_diff(left, right)) == right`。
## 许可证
MIT
---
<a id="english"></a>
## English
Structural diff between two dicts, nested keys included.
## Install
```console
pip install 222
```
## Usage
```python
from p222 import apply_diff, dict_diff
left = {"db": {"port": 5432, "host": "a"}, "tags": ["x"], "gone": 1}
right = {"db": {"port": 6543, "host": "a"}, "tags": ["y"], "new": 2}
dict_diff(left, right)
# {'db.port': ('changed', 5432, 6543),
# 'gone': ('removed', 1, None),
# 'new': ('added', None, 2),
# 'tags': ('changed', ['x'], ['y'])}
apply_diff(left, dict_diff(left, right)) == right # True
```
## Notes
The import name is `p222` because the distribution starts with a digit. Nested dicts are compared recursively and reported as dotted paths such as `db.pool.size`. `apply_diff` reverses the diff, so the round trip is exact.
## License
MIT
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.10 | Python |
نحوه نصب
نصب پکیج whl 222-0.0.4:
pip install 222.whl
نصب پکیج tar.gz 222-0.0.4:
pip install 222.tar.gz