Skip to main content

一个简单的基于 JSON 文件的键-值存储类

Project description

描述

一个简单的基于 JSON 文件的键-值存储类。它提供了一种方便的方法来操作 JSON 文件,与操作 Python 字典类似,但每次修改后都会自动进行持久化。

作者

作者: 许灿标

链接: 主页 | Github | PyPi | 微信 | 邮箱 | 捐赠

教程

安装或更新

pip install --upgrade arts

导入

from arts import DictFile

初始化

首先,初始化一个实例:

stock = DictFile(rf'C:\bpath\downloads\test_arts.json')

增加键

要增加一个键,只需像操作字典那样赋值:

stock['hat'] = 10
stock['shoe'] = 20
stock['jacket'] = 30

更新键

更新一个键的方法与增加一个键的方法相同:

stock['jacket'] = 31

查询键

要查询键的值,只需像操作字典那样:

jacket_count = stock['jacket']

如果该键不存在,此操作会抛出一个 KeyError 。为避免错误,你可以使用 get 方法:

mouse_count = stock.get('mouse', default=0)

删除键

使用 pop 方法删除指定的键并返回其值:

shoe_count = stock.pop('shoe')

如果指定的键不存在,pop 会抛出一个 KeyError 。如果你想避免这个错误并在键不存在时返回一个默认值,可以这样做:

mouse_count = stock.pop('mouse', 0)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arts-2025.4.12.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

arts-2025.4.12-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file arts-2025.4.12.tar.gz.

File metadata

  • Download URL: arts-2025.4.12.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for arts-2025.4.12.tar.gz
Algorithm Hash digest
SHA256 fed8214a325015ee22d4c2912571a98c32860187c902015bfd2fc5e468ab9943
MD5 2efe8261aa9d5dd79f62adbf0cf79d0d
BLAKE2b-256 d001359ef39fd684133352a9e6826825f4ba25900dfbce01090b53cbc155021e

See more details on using hashes here.

File details

Details for the file arts-2025.4.12-py3-none-any.whl.

File metadata

  • Download URL: arts-2025.4.12-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for arts-2025.4.12-py3-none-any.whl
Algorithm Hash digest
SHA256 398d0649fe40d04599090a47c03a3e8dd898f29ce8231604aa6216f29c714ad3
MD5 7774796e733145c16d485cde746b7882
BLAKE2b-256 f2929dff3487b99dfd302d7b0fe7cf5dffeb7c1b4a3c8e4449b23bea1ecf3a60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page