PermissiveDict
Dictionary class with loose rules for returning an attribute or a requested key value.
Note: may resort to iterating the dict values to find the matching requested key, so is potentially slow.
Key is first directly found using the exact key, and then loose rules are used.
Installing
pip install permissive-dict
Key Search Rules:
- Keys compared without regard to case.
- Spaces, underscores, full-stops and dashes are equivalent in a requested key.
- Requested key is converted to str and stripped for wild card searching.
- Items in the list can be retrieved by, get, attribute_access, call or array requested_key.
- First matching element is returned.
- Default of '' is used instead of dict standard None or raising KeyError
- Multiple keys can be supplied separated with , (comma)
Example:
from permissive_dict import PermissiveDict
a = PermissiveDict({'A B': 2, 4: 4})
a.get('A_b') == a['a_b'] == a['A b'] == a['A_B'] == a['a-b '] == a['a.b '] == a.a_b == a.A_b == a('a-b')
a.get('blue,4') == 4
a.get('4') == a[4] == a(4) == a('4')
Items with multiple wildcard keys matching in the dictionary will return the first item found.
Keys can be accessed as attributes, array index, get() or by calling the instance variable.
Key and value can be set as an attribute.
Example:
a = PermissiveDict()
a.hello = 4
a.hello == a['hello'] == a('hello') == a.get('HellO')
Converting an entire list of dicts
An entire list of dictionaries can be converted to PermissiveDict using
the convert_list method. NOTE: no deep conversion is done and child
dictionaries are not converted.
Example:
list_of_dicts = [dict(a=n) for n in range(10)]
permissive_list = PermissiveDict.convert_list(list_of_dicts)
Notes
Only Python 3 is supported.
Release history
1.0.4 Fix missing handling of _ and -
Metadata
Release files for permissive-dict 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| permissive-dict-1.0.4.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| permissive_dict-1.0.4-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 9.5 kB
Release files / permissive-dict-1.0.4.tar.gz
| Download URL | permissive-dict-1.0.4.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b274b982c9dbcb058e9a665b752c9cee4bf4a4d957762ee528daad1eb009a8d
|
|
BLAKE2b-256 checksum How to use checksums |
f8c4928bccb0e7bacc06a0f5b9216ee790f231025d2bc0ab50f034598ca33d35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Release files / permissive_dict-1.0.4-py2.py3-none-any.whl
| Download URL | permissive_dict-1.0.4-py2.py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
6a0d0330be7bf6a496310d8c07eb3bd3aa1a782b7322b1393a912e7ae364e508
|
|
BLAKE2b-256 checksum How to use checksums |
213b03b0f92f754515166c74f0327fa72861ba143790baa72bc120adef60f250
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|