dictionary with fully evaluated keys
Project description
This package provides a NamespaceDict mapping which fully evaluates keys using Python. For example, it can perform nested lookups, attribute lookups, and tuple splicing:
>>> from namespacedict import NamespaceDict >>> >>> # create a new namespace >>> ns = NamespaceDict() >>> >>> # nested lookup from a list >>> ns['x'] = [1, 2, 3] >>> ns['x[1]'] 2 >>> # set a docstring attribute >>> ns['y'] = lambda x: x >>> ns['y.__doc__'] = 'my function' >>> >>> # set three items from a tuple >>> ns['a, b, c'] = 'A', 'B', 'C' >>> ns['b'] 'B'
Keys are parsed in a safe way using Python’s AST library. It is thus possible to create complex dictionary queries as expected:
>>> ns['one'] = 1 >>> ns['two'] = 2 >>> ns['x[0:two]'] = 5, 4 >>> ns['x[::-one]'] [3, 4, 5]
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
namespacedict-0.1.0.tar.gz
(3.5 kB
view details)
File details
Details for the file namespacedict-0.1.0.tar.gz
.
File metadata
- Download URL: namespacedict-0.1.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c57f6a89f0236da53c3025e9b89b15716db0e0466d4749a4dbe68b40f181f831 |
|
MD5 | 4c2b9e3262974a71855d2122bd12a0e6 |
|
BLAKE2b-256 | 9e008a858d0ad559cf0af12c92b3cfb590880f6f9125d9d5f845d0790583d12e |