Skip to main content

DOTC (like Yahtzee) - Access Nested Dicts and Lists via Dots

Project description

dotc

DOTC (like Yahtzee) - Access Nested Dicts and Lists via Dots (Dotc objects all the way down)

pip install dotc python from dotc import Dotc

Converts Python Data Structures (dicts, lists, scalars) to a nested object structure

- can access nested data with dot notation and _listindex for lists

  - example:
        data = {'a':1,'b':{'c':3,'d':[4,5,'6']}}
        node = 'root' # optional node name; defaults to '', but child nodes get their names from keys
        o = Dotc(data,node) or o = Dotc(data=data,node='root')
        o.a returns 1
        o.b.c returns 3
        o.b.d._0 returns 4

- if _strict=0 (default), accessing a non-existent attribute returns _default instead of raising AttributeError

  - example using o from above:
        o.b.x returns None (the default _default value)

- if _strict=1, setting a value on a non-existent path raises an exception

- if setting _strict=1 after instantiation, it has no effect on child nodes (TODO: fix with @property(s))

- use ._ to get fully resolved data structure otherwise ._val is the scalar/resultant value if set
    otherwise the Dotc object is returned so you can keep traversing with dot notation

  - example using d from above:
        o._ returns {'a':1,'b':{'c':3,'d':[4,5,'6']}}
        o.b._ returns {'c':3,'d':[4,5,'6']} where as d.b returns the Dotc object itself so that:
        o.b.d._ returns [4,5,'6']

- explore (using o from above) passing in the dotc object (or not for self) 
    and optionally v for verbosity:
    
    >>> o._show()
    {'_key_ct': 2,
    '_ls_ct': 0,
    '_node': 'root',
    '_parent': None,
    '_strict': 0,
    '_val': None}

    >>> o._show(v=1)
    {'_key_ct': 2,
    '_ls_ct': 0,
    '_node': 'root',
    '_parent': None,
    '_strict': 0,
    '_val': None,
    'a': 1,
    'b': Dotc( "b", _val=None, _key_ct=2, _ls_ct=0 )}

    >>> o._show(o.b.d, v=1)
    {'_0': 4,
    '_1': 5,
    '_2': '6',
    '_key_ct': 0,
    '_ls_ct': 3,
    '_node': 'd',
    '_parent': 'b',
    '_strict': 0,
    '_val': None}

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

dotc-0.3.4.tar.gz (501.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dotc-0.3.4-py3-none-any.whl (498.3 kB view details)

Uploaded Python 3

File details

Details for the file dotc-0.3.4.tar.gz.

File metadata

  • Download URL: dotc-0.3.4.tar.gz
  • Upload date:
  • Size: 501.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for dotc-0.3.4.tar.gz
Algorithm Hash digest
SHA256 cf04e148645c0cca31fbaf7c8c4f8fa3ff0b47cee0a44ac8ebe2aba879c61817
MD5 bf32aa3bb24b5dc6010c6e97d7146b0f
BLAKE2b-256 16b6f0ab1dfb491cc9064b0507242cd6c166c7537f380a81ee2f962e05bbd537

See more details on using hashes here.

File details

Details for the file dotc-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: dotc-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 498.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for dotc-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 33acc6f98949f5c662fcb60e45fc13bd25296a4f77d1f5f1277c5349d0b9093b
MD5 36dd3497d368e3b057f8f69d53361eac
BLAKE2b-256 d8202de4af032735dadcd72b455b03b89c7772ffa98b2004c1a09d4a3f065fd3

See more details on using hashes here.

Supported by

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