`MetadataManager` 是一个简单的 JSON 元数据管理器,旨在方便地读取、写入和操作 JSON 文件。它提供了一系列方法来管理嵌套的 JSON 数据结构,支持添加、删除、读取和更新操作。
Project description
MetadataManager 使用说明
简介
MetadataManager 是一个简单的 JSON 元数据管理器,旨在方便地读取、写入和操作 JSON 文件。它提供了一系列方法来管理嵌套的 JSON 数据结构,支持添加、删除、读取和更新操作。
特性
- 读取和解析 JSON 文件
- 保存和更新 JSON 文件
- 支持嵌套键的访问
- 支持从列表中添加和删除元素
- 可选的唯一性检查以防止重复项
安装
确保您已安装 Python 3.x。将 metadata_manager.py 文件下载到您的项目目录中。
# 克隆或下载代码
git clone https://github.com/amumu2022/MetadataManager.git
cd https://github.com/amumu2022/MetadataManager.git
使用方法
初始化
首先,您需要创建一个 MetadataManager 实例。您可以指定缓存目录的名称,默认为 cache_path。
from metadata_manager import MetadataManager
manager = MetadataManager(cache_dir='your_cache_directory')
读取数据
使用 read 方法读取 JSON 文件中的数据。您可以提供多个键以访问嵌套数据。
data = manager.read('your_file_name', 'key1', 'key2')
如果未提供键,则返回整个字典。
添加或更新数据
使用 add 方法添加或更新指定嵌套键的值。
manager.add('your_file_name', 'key1', 'key2', value='your_value')
删除数据
使用 delete 方法删除指定嵌套键的值。
success = manager.delete('your_file_name', 'key1', 'key2')
向列表中添加元素
使用 add_to_list 方法向指定键的列表中添加元素。可以选择设置 unique 参数以防止添加重复项。
manager.add_to_list('your_file_name', 'your_list_key', value='new_value', unique=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file metadatamanager-0.1.0.tar.gz.
File metadata
- Download URL: metadatamanager-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.10.8 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aea7ec732db45c1130d9acf52c86d416a7d30878e45efbe5620593519e6bc3e7
|
|
| MD5 |
f5207d0e8fba1abd68ba368f13613292
|
|
| BLAKE2b-256 |
e5927bcbcfa0f0ffa13e4aa9f680768182b14bbd0c3cb41e184b44b1d293632c
|
File details
Details for the file metadatamanager-0.1.0-py3-none-any.whl.
File metadata
- Download URL: metadatamanager-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.10.8 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b0e24a6ee5a5d34d8574173432ce433aa95d08aeec41ba030cd897c79107c2
|
|
| MD5 |
5426c19b821aec7586a3379a1e37068f
|
|
| BLAKE2b-256 |
e741fbbcd90c1a583a9f0da930d86a262010e6b0e63ad3f553bfe3e394c9b6b2
|