A subclass of dict that allows object-style access to its entries
Project description
attribute_dict
A subclass of dict that allows object-style access to its entries.
Installation
pipenv install attribute_dict
Usage
from attribute_dict import AttributeDict
sample_dict = AttributeDict({'foo': 'bar'})
sample_dict # => AttributeDict({'foo': 'bar'})
# The object is just subclassed from dict, and has all of the standard functions
isinstance(sample_dict, dict) # => True
# Create a new AttributeDict by "stacking" iterables
# Each iterable will overwrite keys in the previous one (kwargs are processed last!)
sample_dict = AttributeDict({'foo': 'foo'}, {'foo': 'ba', 'bar': 'foo'}, {'foo': 'bar'}, {'foobar': 'bar'}, foobar='foo')
# => AttributeDict({'foo': 'bar', 'bar': 'foo', 'foobar': 'foo'})
# Create a new AttributeDict by shallow-copying an existing one
new_sample_dict = sample_dict.copy()
new_sample_dict # => AttributeDict({'foo': 'bar', 'bar': 'foo', 'foobar': 'foo'})
isinstance(new_sample_dict, AttributeDict) # => True
# NOTE: Child values are NOT processed!
sample_dict = AttributeDict({'foo': iterable_two})
sample_dict # => AttributeDict({'foo': {'foo': 'ba', 'bar': 'foo'}})
sample_dict.foo # => {'foo': 'ba', 'bar': 'foo'}
sample_dict.__class__.__name__ # => 'AttributeDict'
sample_dict.foo.__class__.__name__ # => 'dict'
Tests
Tests use nose2. Clone the Github project. Install dev dependencies, and run tests using the nose2 command.
pipenv install --dev
pipenv shell
nose2
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
attribute_dict-1.0.0.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file attribute_dict-1.0.0.tar.gz
.
File metadata
- Download URL: attribute_dict-1.0.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd6c646a3803a0c2350e44c6e0cd193460d7fca18944675633d4882c1f0ab509 |
|
MD5 | 0d0b5782b288cecf1ec52506b25f3d79 |
|
BLAKE2b-256 | 1275f80f88f1c3deb460122685dd149bd26ee56d18463ea0f49c01c7f2fc9256 |
File details
Details for the file attribute_dict-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: attribute_dict-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 205971dd6d418a0d03514bdf296099d6eb31795a9ac3189c5a646227f67074e7 |
|
MD5 | a46d6a37afbe5fd3b76e19fd785122e6 |
|
BLAKE2b-256 | 006373959ef6c40cd9f674bceb3c9d6087182ff57e58fc16c7568884757e0570 |