Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bcj committed Apr 9, 2015
1 parent e00c130 commit 39a1e5d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ v0.5.1, 2014/07/14 -- tox for local testing, README fix, 0.5.0 no longer from th
v1.0.0, 2014/08/18 -- Development Status :: 5 - Production/Stable
v1.1.0, 2014/10/29 -- has_key support to match python2 dicts (by Nikolaos-Digenis Karagiannis @Digenis)
v1.2.0, 2014/11/26 -- Happy U.S. Thanksgiving, now you can pickle AttrDict! (by @jtratner), bugfix: default_factory will no longer be erroneously called when accessing private attributes.
v2.0, 2015/04/09 -- Happy PyCon. An almost-complete rewrite. Hopefully in a good way
60 changes: 1 addition & 59 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ Or from Github::
$ cd AttrDict
$ python setup.py install

Documentation
=============

Documentation is available at http://attrdict.readthedocs.org/en/latest/

Basic Usage
===========
AttrDict comes with three different classes, `AttrMap`, `AttrDict`, and
Expand Down Expand Up @@ -146,12 +141,7 @@ AttrDefault also has a `pass_key` option that passes the supplied key to the

Merging
-------
All three Attr classes


Merging
-------
AttrDicts can be merged with each other or other dict objects using the
All three Attr classes can be merged with eachother or other Mappings using the
``+`` operator. For conflicting keys, the right dict's value will be
preferred, but in the case of two dictionary values, they will be
recursively merged::
Expand Down Expand Up @@ -200,54 +190,6 @@ When merging an AttrDict with another mapping, this behavior will be disabled
if at least one of the merged items is an AttrDict that has set ``recursive``
to ``False``.

DefaultDict
===========

AttrDict supports defaultdict-style automatic creation of attributes::

> adict = AttrDict(default_factory=list)
> adict.foo
[]

Furthermore, if ``pass_key=True``, then the key will be passed to the function
used when creating the value::

> adict = AttrDict(default_factory=lambda value: value.upper(), pass_key=True)
> adict.foo
'FOO'

load
====
A common usage for AttrDict is to use it in combination with settings files to
create hierarchical settings. attrdict comes with a load function to make this
easier::

from attrdict import load

settings = load('settings.json')

By default, ``load`` uses ``json.load`` to load the settings file, but this can
be overridden by passing ``load_function=YOUR_LOAD_FUNCTION``.

``load`` supports loading from multiple files at once. This allows for
overriding of default settings, e.g.::

from attrdict import load
from yaml import safe_load

# config.yaml =
# emergency:
# email: [email protected]
# message: Something went wrong
#
# user.yaml =
# emergency:
# email: [email protected]
settings = load('config.yaml', 'user.yaml', load_function=safe_load)

assert settings.email == '[email protected]'
assert settings.message == 'Something went wrong'

License
=======
AttrDict is released under a MIT license.

0 comments on commit 39a1e5d

Please sign in to comment.