A small utility for wrapping trees (nested dict/list) that allows filesystem-like path access, including walking up with "../".
Project description
FS Path Tree
A simple class to allow filesystem-style path access to nested dict/list structures, including support for walking "up" the tree with '..'.
Example:
config = fspathtree()
config.update( { 'desc' : "example config"
, 'time' : { 'N' : 50
, 'dt' : 0.01 }
, 'grid' : { 'x' : { 'min' : 0
, 'max' : 0.5
, 'N' : 100 }
, 'y' : { 'min' : 1
, 'max' : 1.5
, 'N' : 200 }
}
} )
# elements are accessed in the same was as a dict.
assert config['desc'] == "example config"
# sub-elements can also be accessed the same way.
assert config['grid']['x']['max'] == 0.5
# but they can also be accessed using a path.
assert config['grid/x/max'] == 0.5
# get a sub-element in the tree.
x = config['grid/x']
# again, elements of grid/x are accessed as normal.
assert x['max'] == 0.5
# but we can also access elements that are not in this branch.
assert x['../y/max'] == 1.5
# or reference elements from the root of the tree.
assert x['/time/N'] == 50
Install
You can install the latest release with pip
.
$ pip install fspathtree
Or, even better, using pipenv
$ pipenv install fspathtree
Design
The fspathtree
is a small wrapper class that can wrap any nested tree data structure. The tree that is wrapped can be accessed with
the .tree
attribute. This is an improvement over the old fspathdict.pdict
class, which stored nodes internally as fspathdict.pdict
instances
and required "converting" to and from the standard python dict and list types.
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
Built Distribution
Hashes for fspathtree-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bf0356c37029d97fa365ae7d39d682d7671fd3e7fa72363210cbaf2611191dc |
|
MD5 | d158ea7b49515d4b4c170790612dc7da |
|
BLAKE2b-256 | fd07925f778ca3bf204462b0b0f98eeb55fd5dafc5dbac3691d0ef6084b1abd0 |