Access dict values as attributes (works recursively). A Javascript-like properties dot notation for python dicts.
USAGE
>>> from easydict import EasyDict as edict
>>> d = edict({'foo':3, 'bar':{'x':1, 'y':2}})
>>> d.foo
3
>>> d.bar.x
1
>>> d = edict(foo=3)
>>> d.foo
3
Very useful when exploiting parsed JSON content !
>>> from easydict import EasyDict as edict
>>> from simplejson import loads
>>> j = """{
"Buffer": 12,
"List1": [
{"type" : "point", "coordinates" : [100.1,54.9] },
{"type" : "point", "coordinates" : [109.4,65.1] },
{"type" : "point", "coordinates" : [115.2,80.2] },
{"type" : "point", "coordinates" : [150.9,97.8] }
]
}"""
>>> d = edict(loads(j))
>>> d.Buffer
12
>>> d.List1[0].coordinates[1]
54.9
Can set attributes as easily as getting them
>>> d = EasyDict() >>> d.foo = 3 >>> d.foo 3
Instance and class attributes are accessed like usual
>>> class Flower(EasyDict):
... power = 1
...
>>> f = Flower({'height': 12})
>>> f.power
1
>>> f['power']
1
LICENSE
Lesser GNU Public License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
easydict-1.4.tar.gz
(2.5 kB
view details)
File details
Details for the file easydict-1.4.tar.gz.
File metadata
- Download URL: easydict-1.4.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ae0f0c3ffe2cf6228dd537ea2fd7707d81ec4e5e39606369d561aaf1578049b
|
|
| MD5 |
349dd4050d5dc217cff12536648d88d0
|
|
| BLAKE2b-256 |
77a1dfe10522accfc2f6f27bee6144ac20f4852d6d177ec9dce1152b989d5228
|