-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
bunch | ||
===== | ||
|
||
Bunch is a dictionary that supports attribute-style access, a la JavaScript. | ||
|
||
>>> b = Bunch() | ||
>>> b.hello = 'world' | ||
>>> b.hello | ||
'world' | ||
>>> b['hello'] += "!" | ||
>>> b.hello | ||
'world!' | ||
>>> b.foo = Bunch(lol=True) | ||
>>> b.foo.lol | ||
True | ||
>>> b.foo is b['foo'] | ||
True | ||
|
||
|
||
Dictionary Methods | ||
------------------ | ||
|
||
A Bunch is a subclass of ``dict``; it supports all the methods a ``dict`` does: | ||
|
||
>>> b.keys() | ||
['foo', 'hello'] | ||
|
||
Including ``update()``: | ||
|
||
>>> b.update({ 'ponies': 'are pretty!' }, hello=42) | ||
>>> print repr(b) | ||
Bunch(foo=Bunch(lol=True), hello=42, ponies='are pretty!') | ||
|
||
As well as iteration: | ||
|
||
>>> [ (k,b[k]) for k in b ] | ||
[('ponies', 'are pretty!'), ('foo', Bunch(lol=True)), ('hello', 42)] | ||
|
||
And "splats": | ||
|
||
>>> "The {knights} who say {ni}!".format(**Bunch(knights='lolcats', ni='can haz')) | ||
'The lolcats who say can haz!' | ||
|
||
|
||
Conversion | ||
---------- | ||
|
||
Bunch converts easily to (``unbunchify/Bunch.toDict``) and from (``bunchify/Bunch.fromDict``) a normal ``dict``, making it easy to cleanly serialize them to JSON or YAML. | ||
|
||
|
||
Import Safe | ||
----------- | ||
|
||
It is safe to ``import *`` from this module. You'll get: | ||
|
||
__all__ = ('Bunch', 'bunchify','unbunchify') | ||
|
||
|
||
Feedback | ||
-------- | ||
|
||
Open a ticket on [github](http://github.com/dsc/bunch), or send me an email at [[email protected]](mailto:[email protected]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
#! python | ||
from setuptools import setup, find_packages | ||
import os | ||
from distutils.core import setup | ||
|
||
version = "1.0.0" | ||
|
||
# Read the long description from the README.txt | ||
here = os.path.abspath(os.path.dirname(__file__)) | ||
f = open(os.path.join(here, 'README.rst')) | ||
readme = f.read() | ||
f.close() | ||
|
||
|
||
setup( | ||
name = "bunch", | ||
description = "A dot-accessible dictionary (a la JavaScript objects)", | ||
version = "1.0.0", | ||
license = 'MIT', | ||
version = version, | ||
author = "David Schoonover", | ||
author_email = "[email protected]", | ||
long_description = """ | ||
A dot-accessible dictionary (a la JavaScript objects). | ||
""", | ||
long_description = readme, | ||
url = "http://tire.less.ly/hacking/bunch", | ||
platform = 'Any', | ||
download_url = "http://pypi.python.org/packages/source/B/bunch/bunch-%s.tar.gz" % version, | ||
|
||
packages=['bunch',], | ||
zip_safe = True, | ||
keywords = ['dict', 'bunch', 'mapping', 'utilities',], | ||
classifiers = [ | ||
'Programming Language :: Python', | ||
'Development Status :: 5 - Production/Stable', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Intended Audience :: Developers', | ||
'Topic :: Software Development', | ||
'Topic :: Software Development :: Libraries', | ||
'Topic :: Utilities', | ||
] | ||
license = 'MIT', | ||
zip_safe = True, | ||
) | ||
|