Skip to main content

DICT-OPERATION allow you select data value from a dict-instance with dot separated path, and update.

Project description

dictop

DICT-OPERATION allow you select data value from a dict-instance with dot separated path, and update.

Install

pip install dictop

Usage

    from dictop import update
    from dictop import select

    data = {}
    update(data, "a.b.c", 2)
    assert select(data, "a.b.c") == 2

Core Functions

  1. select
    select(target, path, default=None, slient=True)
  1. update
    update(target, path, value)

Unit Tests

# tests.py

import unittest
import dictop

class DictopTest(unittest.TestCase):


    def test01(self):
        data = {
            "a": {
                "b": "value",
            }
        }
        assert dictop.select(data, "a.b") == "value"
        assert dictop.select(data, "a.c") is None
    
    def test02(self):
        data = {
            "a": [{
                "b": "value",
            }]
        }
        assert dictop.select(data, "a.0.b") == "value"
        assert dictop.select(data, "a.1.b") is None

    def test03(self):
        data = [1,2,3]
        assert dictop.select(data, "0") == 1
        assert dictop.select(data, "4") is None

    def test04(self):
        data = {}
        dictop.update(data, "a.b.c", "value")
        dictop.select(data, "a.b.c") == "value"
    
    def test05(self):
        data = []
        dictop.update(data, "1.a.b", "value")
        assert data[1]["a"]["b"] == "value"

Releases

0.1.0 2018/03/20

  • First release.

0.1.1 2018/03/20

0.1.2 2018/04/02

0.1.3 2018/04/18

0.1.4 2019/04/12

  • Update.

0.2.1 2022/01/08

  • Fix license file missing problem.

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

dictop-0.2.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

dictop-0.2.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file dictop-0.2.1.tar.gz.

File metadata

  • Download URL: dictop-0.2.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for dictop-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bad57fb163932bd36dddd51e7ec0d4dee3664ee842f4866d03f471fc0bbd9cc6
MD5 b638e53f762295d419c8d0d422d1fbf3
BLAKE2b-256 4043f1dca5ae5c641994f2db8ea0c090bd0ab1fc05d0974e11e7e959e7810b95

See more details on using hashes here.

File details

Details for the file dictop-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dictop-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for dictop-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 99aa16669ea4aa849aab937769b166372ac5055e97ffa09da6badc9a5d50e9d0
MD5 6785a8c6731a2f359953f0e2d1cc09c6
BLAKE2b-256 afc5253c5a21c037c5fad0cf33065e58110b5a3bdd335eb878f30276ac824f7d

See more details on using hashes here.

Supported by

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