Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added munchify to the readme #102

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ Or you can use ``DefaultFactoryMunch`` to specify a factory for generating missi
```


Converting an Existing Dictionary to Munch
------------------------------------------

If you have an existing dictionary that you've computed and want to convert it into a Munch object, you can use the `munchify` function. This function recursively transforms a dictionary into a Munch object via copy. Here's an example:

```python
>>> b = munchify({'urmom': {'sez': {'what': 'what'}}})
>>> b.urmom.sez.what
'what'
```

The `munchify` function can handle intermediary dicts, lists, and tuples (as well as their subclasses). However, your mileage may vary with custom data types. Here's a more complex example:

```python
>>> b = munchify({ 'lol': ('cats', {'hah':'i win again'}),
... 'hello': [{'french':'salut', 'german':'hallo'}] })
>>> b.hello[0].french
'salut'
>>> b.lol[1].hah
'i win again'
```


Miscellaneous
-------------

Expand Down