Comments (2)
Hey Jason,
Happy to hear you're enjoying this package.
The goal of munch is to be a simple alternative to python's standard dict that supports attribute-style access, without too many additional features besides that.
The merge function idea you suggested sounds really cool, but unfortunately it would be a bit of a feature creep to add it to Munch.
You can always extend the Munch class using inheritance or composition and add this functionality in your own repository if you'd like.
Best of luck,
David
from munch.
Thank you, David,
I use below code to merge 2 dict recursively, then create a new munch object from the new dict object.
def dict_merge(dct, merge_dct):
# https://gist.github.com/angstwad/bf22d1822c38a92ec0a9
""" Recursive dict merge. Inspired by :meth:dict.update()
, instead of
updating only top-level keys, dict_merge recurses down into dicts nested
to an arbitrary depth, updating keys. The merge_dct
is merged into
dct
.
:param dct: dict onto which the merge is executed
:param merge_dct: dct merged into dct
:return: None
"""
for k, v in merge_dct.items():
if (k in dct and isinstance(dct[k], munch.Mapping) and isinstance(merge_dct[k], munch.Mapping)):
dict_merge(dct[k], merge_dct[k])
else:
dct[k] = merge_dct[k]
The code doesn't process list(tuple), but it is enough for me now.
Regards,
Jason.
from munch.
Related Issues (20)
- DefaultMunch getter now returns None instead of DefaultValue HOT 2
- munch.fromYAML issue HOT 1
- is Munch thread safe for reading? HOT 1
- Setup.py Update HOT 1
- What are the recommended type annotations? HOT 9
- Undeclared dependency on setuptools (pkg_resources) HOT 3
- DefaultMunch TypeError HOT 2
- _make is part of namedtuple's contract, not tuple HOT 2
- A warning/error should be given if an element has the key "items" HOT 1
- version parsing HOT 1
- Cannot import Munch if the wheel doesn't come from a regular source HOT 1
- Describe Installation / Link out to Pypi page HOT 1
- New version on PyPi with RecursiveMunch HOT 4
- Munch cannot recursively fetch values beyond first level when passed with a dot notation. HOT 2
- mucnh does not seem to work when called using python's exec method HOT 1
- Munch does not support local version identifiers
- Make `munch.Munch` a Generic and add type annotations
- munchify broken?
- Need exception thrown for missing attributes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from munch.