Skip to main content

Dict class with dot notation (like attributes) for accessing nested values

Project description

Build Status Coverage Status # DotAccessDict

DotAccessDict class can handle nested dictionaries with arbitray number of dicts and lists, nested inside each other.

Usage:

>>> from ddict import DotAccessDict
>>> d = DotAccessDict()
>>> d
{}
>>> d.person
{}
>>> d.person.name = 'Jack'
>>> d
{'person': {'name': 'Jack'}}
>>> d['person']['name']
'Jack'
>>> d['person'].name
'Jack'
>>> d.person['name']
'Jack'
>>> joe = dict(name='Joe', age=18)
>>> d.person.brothers = [joe, 'John', 'Pat']
>>> d.person.brothers[0].age
18
>>> d.get('person.brothers[1]')
'John'
>>> d.set('person.brothers[2]', 'James')
>>> d.person.brothers[2]
'James'
>>> d.flatten()
{'person.brothers[0].age': 18,
 'person.brothers[0].name': 'Joe',
 'person.brothers[1]': 'John',
 'person.brothers[2]': 'James',
 'person.name': 'Jack'}

Similar works:

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

ddict-0.1.2.tar.gz (3.8 kB view hashes)

Uploaded Source

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