A Python `dict` with a merge() method.
Project description
mergedict - A Python dict with a merge() method
A MergeDict is a dict with a merge() method. merge() is like dict.update()…
from mergedict import MergeDict d1 = MergeDict({'a': 1, 'b': 'one'}) d1.merge({'a':2, 'c': [2]}) assert d1 == {'a': 2, 'c': [2], 'b': 'one'}
A MergeDict can be subclassed to create custom “merge” operations based on the type of an item value.
from mergedict import MergeDict class SumDict(MergeDict): @MergeDict.dispacth(int) def merge_int(this, other): return this + other d2 = MergeDict({'a': 1, 'b': 'one'}) d2.merge({'a':2, 'b': 'two'}) assert d2 == {'a': 3, 'b': 'two'}
mergedict module comes with a ConfigDict that will extend/update lists/sets/dicts.
from mergedict import ConfigDict d3 = ConfigDict({'a': 1, 'my_list': [1, 2]}) d3.merge({'a':2, 'my_list': [3, 4]}) assert d3 == {'a': 2, 'my_list': [1, 2, 3, 4]}
Project Details
Project management on github - https://github.com/schettino72/mergedict/
license
The MIT License Copyright (c) 2013 Eduardo Naufel Schettino
see LICENSE file
developers / contributors
Eduardo Naufel Schettino
install
$ pip install pyterm
or download and:
$ python setup.py install
tests
To run the tests:
$ py.test
CHANGES
0.1.0 2013-12-15
initial release
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mergedict-0.1.0.tar.gz
(3.4 kB
view details)
File details
Details for the file mergedict-0.1.0.tar.gz
.
File metadata
- Download URL: mergedict-0.1.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70786d867d41016f190ee5eaf36188b0a1ced52aad097d1598b578c5b22f6b7a |
|
MD5 | 6b8bb1ffecba71f141f017e1d5cf284e |
|
BLAKE2b-256 | 17029885d41e20ecb290233f999a0a872ab11c4cef8df03af2b26df9e5212de4 |